Dotclear

Changeset 3915:a57821ba9ef1


Ignore:
Timestamp:
11/05/18 16:40:40 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Switching from inline JS variables to JSON script. A step ahead…

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • admin/_charte.php

    r3776 r3915  
    2323    <link rel="icon" type="image/png" href="images/favicon96-login.png" /> 
    2424<?php 
     25$js = []; 
    2526if ($core->auth->user_prefs->interface->darkmode) { 
    2627    echo dcPage::cssLoad('style/default-dark.css'); 
     
    2930} 
    3031if ($core->auth->user_prefs->interface->htmlfontsize) { 
    31     echo 
    32     '<script type="text/javascript">' . "\n" . 
    33     dcPage::jsVar('dotclear_htmlFontSize', $core->auth->user_prefs->interface->htmlfontsize) . 
    34         "</script>\n"; 
     32    $js['htmlFontSize'] = $core->auth->user_prefs->interface->htmlfontsize; 
    3533} 
     34// Set some JSON data 
     35echo dcUtils::jsJson('dotclear_init', $js); 
     36echo dcPage::jsUtil(); 
    3637?> 
    3738    <script type="text/javascript" src="js/jquery/jquery.js"></script> 
  • admin/js/_index.js

    r3908 r3915  
    206206  } 
    207207 
    208   if (!dotclear.noDragDrop) { 
     208  if (!dotclear.data.noDragDrop) { 
    209209    // Dashboard boxes and their children are sortable 
    210210    const set_positions = function(sel, id) { 
  • admin/js/common.js

    r3882 r3915  
    1 /*global $, jQuery, dotclear_htmlFontSize */ 
     1/*global $, jQuery, getData */ 
    22/*exported chainHandler */ 
    33'use strict'; 
     4 
     5/* Get PreInit JSON data */ 
     6const dotclear_init = getData('dotclear_init'); 
    47 
    58/* Set some CSS variables here 
    69-------------------------------------------------------- */ 
    710// set base font-size of body (62.5% default, usually : 50% to 75%) 
    8 if (typeof dotclear_htmlFontSize !== 'undefined') { 
    9   document.documentElement.style.setProperty('--html-font-size', dotclear_htmlFontSize); 
     11if (typeof dotclear_init.htmlFontSize !== 'undefined') { 
     12  document.documentElement.style.setProperty('--html-font-size', dotclear_init.htmlFontSize); 
    1013} 
    1114/* ChainHandler, py Peter van der Beken 
     
    549552-------------------------------------------------------- */ 
    550553$(function() { 
     554  // Store preinit DATA in dotclear object 
     555  dotclear.data = dotclear_init; 
     556  // Get other DATA 
     557  Object.assign(dotclear.data, getData('dotclear')); 
     558 
    551559  // remove class no-js from html tag; cf style/default.css for examples 
    552560  $('body').removeClass('no-js').addClass('with-js'); 
     
    629637  }); 
    630638  // Advanced users 
    631   if (dotclear.hideMoreInfo) { 
     639  if (dotclear.data.hideMoreInfo) { 
    632640    $('.more-info,.form-note:not(.warn,.warning,.info)').addClass('no-more-info'); 
    633641  } 
    634642  // Ajax loader activity indicator 
    635   if (dotclear.showAjaxLoader) { 
     643  if (dotclear.data.showAjaxLoader) { 
    636644    $(document).ajaxStart(function() { 
    637645      $('body').addClass('ajax-loader'); 
  • inc/admin/lib.dc.page.php

    r3913 r3915  
    2424        "static"  => "static-msg"]; 
    2525 
     26    private static function getCore() 
     27    { 
     28        return $GLOBALS['core']; 
     29    } 
     30 
    2631    # Auth check 
    2732    public static function check($permissions) 
    2833    { 
    29         global $core; 
     34        $core = self::getCore(); 
    3035 
    3136        if ($core->blog && $core->auth->check($permissions, $core->blog->id)) { 
     
    4247    public static function checkSuper() 
    4348    { 
    44         global $core; 
     49        $core = self::getCore(); 
    4550 
    4651        if (!$core->auth->isSuperAdmin()) { 
     
    5560    public static function open($title = '', $head = '', $breadcrumb = '', $options = []) 
    5661    { 
    57         global $core; 
     62        $core = self::getCore(); 
     63        $js = []; 
    5864 
    5965        # List of user's blogs 
     
    170176 
    171177        if ($core->auth->user_prefs->interface->darkmode) { 
    172             echo self::jsVars(['dotclear_darkMode' => 1]); 
     178            $js['darkMode'] = 1; 
    173179            echo self::cssLoad('style/default-dark.css'); 
    174180        } else { 
    175             echo self::jsVars(['dotclear_darkMode' => 0]); 
     181            $js['darkMode'] = 0; 
    176182            echo self::cssLoad('style/default.css'); 
    177183        } 
     
    186192                '<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />' . "\n"; 
    187193        } 
    188  
    189194        if ($core->auth->user_prefs->interface->htmlfontsize) { 
    190             echo 
    191             '<script type="text/javascript">' . "\n" . 
    192             self::jsVar('dotclear_htmlFontSize', $core->auth->user_prefs->interface->htmlfontsize) . "\n" . 
    193                 "</script>\n"; 
    194         } 
     195            $js['htmlFontSize'] = $core->auth->user_prefs->interface->htmlfontsize; 
     196        } 
     197        $js['hideMoreInfo'] = (boolean) $core->auth->user_prefs->interface->hidemoreinfo; 
     198        $js['showAjaxLoader'] = (boolean) $core->auth->user_prefs->interface->showajaxloader; 
     199 
     200        $core->auth->user_prefs->addWorkspace('accessibility'); 
     201        $js['noDragDrop'] = (boolean) $core->auth->user_prefs->accessibility->nodragdrop; 
     202 
     203        // Set some JSON data 
     204        echo dcUtils::jsJson('dotclear_init', $js); 
    195205 
    196206        echo 
     
    198208        self::jsToggles() . 
    199209            $head; 
    200  
    201         $core->auth->user_prefs->addWorkspace('accessibility'); 
    202         echo 
    203             '<script type="text/javascript">' . "\n" . 
    204             'dotclear.noDragDrop = '.($core->auth->user_prefs->accessibility->nodragdrop ? 'true' : 'false').';' . "\n" . 
    205             "</script>\n"; 
    206  
    207         if ($core->auth->user_prefs->interface->hidemoreinfo) { 
    208             echo 
    209                 '<script type="text/javascript">' . "\n" . 
    210                 'dotclear.hideMoreInfo = true;' . "\n" . 
    211                 "</script>\n"; 
    212         } 
    213         if ($core->auth->user_prefs->interface->showajaxloader) { 
    214             echo 
    215                 '<script type="text/javascript">' . "\n" . 
    216                 'dotclear.showAjaxLoader = true;' . "\n" . 
    217                 "</script>\n"; 
    218         } 
    219210 
    220211        # --BEHAVIOR-- adminPageHTMLHead 
     
    276267    public static function notices() 
    277268    { 
    278         global $core; 
     269        $core = self::getCore(); 
    279270        static $error_displayed = false; 
    280271 
     
    350341    protected static function getNotification($n) 
    351342    { 
    352         global $core; 
     343        $core = self::getCore(); 
    353344 
    354345        $tag = (isset($n['divtag']) && $n['divtag']) ? 'div' : 'p'; 
     
    363354    public static function close() 
    364355    { 
    365         global $core; 
     356        $core = self::getCore(); 
    366357 
    367358        if (!$GLOBALS['__resources']['ctxhelp']) { 
     
    436427    public static function openPopup($title = '', $head = '', $breadcrumb = '') 
    437428    { 
    438         global $core; 
     429        $core = self::getCore(); 
     430        $js = []; 
    439431 
    440432        # Display 
     
    460452 
    461453        if ($core->auth->user_prefs->interface->darkmode) { 
    462             echo self::jsVars(['dotclear_darkMode' => 1]); 
     454            $js['darkMode'] = 1; 
    463455            echo self::cssLoad('style/default-dark.css'); 
    464456        } else { 
    465             echo self::jsVars(['dotclear_darkMode' => 0]); 
     457            $js['darkMode'] = 0; 
    466458            echo self::cssLoad('style/default.css'); 
    467459        } 
     
    472464        $core->auth->user_prefs->addWorkspace('interface'); 
    473465        if ($core->auth->user_prefs->interface->htmlfontsize) { 
    474             echo 
    475             '<script type="text/javascript">' . "\n" . 
    476             self::jsVar('dotclear_htmlFontSize', $core->auth->user_prefs->interface->htmlfontsize) . "\n" . 
    477                 "</script>\n"; 
    478         } 
     466            $js['htmlFontSize'] = $core->auth->user_prefs->interface->htmlfontsize; 
     467        } 
     468        $js['hideMoreInfo'] = (boolean) $core->auth->user_prefs->interface->hidemoreinfo; 
     469        $js['showAjaxLoader'] = (boolean) $core->auth->user_prefs->interface->showajaxloader; 
     470 
     471        $core->auth->user_prefs->addWorkspace('accessibility'); 
     472        $js['noDragDrop'] = (boolean) $core->auth->user_prefs->accessibility->nodragdrop; 
     473 
     474        // Set JSON data 
     475        echo dcUtils::jsJson('dotclear_init', $js); 
    479476 
    480477        echo 
     
    483480            $head; 
    484481 
    485         $core->auth->user_prefs->addWorkspace('accessibility'); 
    486         echo 
    487             '<script type="text/javascript">' . "\n" . 
    488             'dotclear.noDragDrop = '.($core->auth->user_prefs->accessibility->nodragdrop ? 'true' : 'false').';' . "\n" . 
    489             "</script>\n"; 
    490  
    491         if ($core->auth->user_prefs->interface->hidemoreinfo) { 
    492             echo 
    493                 '<script type="text/javascript">' . "\n" . 
    494                 'dotclear.hideMoreInfo = true;' . "\n" . 
    495                 "</script>\n"; 
    496         } 
    497         if ($core->auth->user_prefs->interface->showajaxloader) { 
    498             echo 
    499                 '<script type="text/javascript">' . "\n" . 
    500                 'dotclear.showAjaxLoader = true;' . "\n" . 
    501                 "</script>\n"; 
    502         } 
    503  
    504482        # --BEHAVIOR-- adminPageHTMLHead 
    505483        $core->callBehavior('adminPageHTMLHead'); 
     
    539517    public static function breadcrumb($elements = null, $options = []) 
    540518    { 
    541         global $core; 
     519        $core = self::getCore(); 
    542520 
    543521        $with_home_link = isset($options['home_link']) ? $options['home_link'] : true; 
     
    566544    public static function message($msg, $timestamp = true, $div = false, $echo = true, $class = 'message') 
    567545    { 
    568         global $core; 
     546        $core = self::getCore(); 
    569547 
    570548        $res = ''; 
     
    639617    public static function helpBlock(...$params) 
    640618    { 
    641         global $core; 
     619        $core = self::getCore(); 
    642620 
    643621        if ($core->auth->user_prefs->interface->hidehelpbutton) { 
     
    648626 
    649627        # --BEHAVIOR-- adminPageHelpBlock 
    650         $GLOBALS['core']->callBehavior('adminPageHelpBlock', $args); 
     628        $core->callBehavior('adminPageHelpBlock', $args); 
    651629 
    652630        if (empty($args)) { 
     
    750728    public static function jsUtil() 
    751729    { 
    752         return self::jsLoad($GLOBALS['core']->blog->getPF('util.js')); 
     730        $core = self::getCore(); 
     731        return self::jsLoad($core->blog->getPF('util.js')); 
    753732    } 
    754733 
    755734    public static function jsToggles() 
    756735    { 
    757         if ($GLOBALS['core']->auth->user_prefs->toggles) { 
    758             $unfolded_sections = explode(',', $GLOBALS['core']->auth->user_prefs->toggles->unfolded_sections); 
     736        $core = self::getCore(); 
     737 
     738        if ($core->auth->user_prefs->toggles) { 
     739            $unfolded_sections = explode(',', $core->auth->user_prefs->toggles->unfolded_sections); 
    759740            foreach ($unfolded_sections as $k => &$v) { 
    760741                if ($v == '') { 
     
    774755    public static function jsCommon() 
    775756    { 
     757        $core = self::getCore(); 
     758 
    776759        $mute_or_no = ''; 
    777         if (empty($GLOBALS['core']->blog) || $GLOBALS['core']->blog->settings->system->jquery_migrate_mute) { 
     760        if (empty($core->blog) || $core->blog->settings->system->jquery_migrate_mute) { 
    778761            $mute_or_no .= 
    779762                '<script type="text/javascript">' . "\n" . 
     
    794777        'jsToolBar = {}, jsToolBar.prototype = { elements : {} };' . "\n" . 
    795778 
    796         self::jsVar('dotclear.nonce', $GLOBALS['core']->getNonce()) . 
     779        self::jsVar('dotclear.nonce', $core->getNonce()) . 
    797780 
    798781        self::jsVar('dotclear.img_plus_src', 'images/expand.png') . 
     
    10291012    public static function jsUpload($params = [], $base_url = null) 
    10301013    { 
     1014        $core = self::getCore(); 
     1015 
    10311016        if (!$base_url) { 
    10321017            $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/', '', $_SERVER['REQUEST_URI']))) . '/'; 
     
    10361021            'sess_id=' . session_id(), 
    10371022            'sess_uid=' . $_SESSION['sess_browser_uid'], 
    1038             'xd_check=' . $GLOBALS['core']->getNonce() 
     1023            'xd_check=' . $core->getNonce() 
    10391024        ]); 
    10401025 
     
    11561141    public static function getPF($file) 
    11571142    { 
    1158         return $GLOBALS['core']->adminurl->get('load.plugin.file', ['pf' => $file]); 
     1143        $core = self::getCore(); 
     1144        return $core->adminurl->get('load.plugin.file', ['pf' => $file]); 
    11591145    } 
    11601146 
    11611147    public static function getVF($file) 
    11621148    { 
    1163         return $GLOBALS['core']->adminurl->get('load.var.file', ['vf' => $file]); 
     1149        $core = self::getCore(); 
     1150        return $core->adminurl->get('load.var.file', ['vf' => $file]); 
    11641151    } 
    11651152 
  • inc/js/util.js

    r3912 r3915  
    22'use strict'; 
    33 
    4 const getData = function(id) { 
     4var getData = getData || function(id, clear = true) { 
     5  let data = {}; 
    56  // Read the JSON-formatted data from the DOM. (from https://mathiasbynens.be/notes/json-dom-csp) 
    67  // To be use with: <script type="application/json" id="myid-data">{"key":value, …}</script> 
    78  const element = document.getElementById(`${id}-data`); 
    8   const string = element.textContent; 
    9   const data = JSON.parse(string); 
    10   // Clear the element’s contents now that we have a copy of the data. 
    11   element.innerHTML = ''; 
     9  if (element) { 
     10    try { 
     11      data = JSON.parse(element.textContent); 
     12      if (clear) { 
     13        // Clear the element’s contents 
     14        element.innerHTML = ''; 
     15      } 
     16    } catch (e) {} 
     17  } 
    1218  return data; 
    1319}; 
  • plugins/dcCKEditor/_post_config.php

    r3897 r3915  
    256256 
    257257    CKEDITOR.on('instanceReady',function(e) { 
    258         if (typeof dotclear_htmlFontSize !== 'undefined') { 
    259             e.editor.document.$.documentElement.style.setProperty('--html-font-size',dotclear_htmlFontSize); 
     258        if (dotclear && dotclear.data && dotclear.data.htmlFontSize) { 
     259            e.editor.document.$.documentElement.style.setProperty('--html-font-size',dotclear.data.htmlFontSize); 
    260260        } 
    261261 
  • plugins/dcCKEditor/inc/dc.ckeditor.behaviors.php

    r3897 r3915  
    6060        dcPage::jsLoad($config_js); 
    6161 
    62         if ($GLOBALS['core']->auth->user_prefs->interface->htmlfontsize) { 
    63             $res .= 
    64             '<script type="text/javascript">' . "\n" . 
    65             dcPage::jsVar('dotclear_htmlFontSize', $GLOBALS['core']->auth->user_prefs->interface->htmlfontsize) . "\n" . 
    66                 "</script>\n"; 
    67         } 
    68  
    6962        return $res; 
    7063    } 
  • plugins/dcLegacyEditor/inc/dc.legacy.editor.behaviors.php

    r3874 r3915  
    139139            "</script>\n"; 
    140140 
    141         if ($GLOBALS['core']->auth->user_prefs->interface->htmlfontsize) { 
    142             $res .= 
    143             '<script type="text/javascript">' . "\n" . 
    144             dcPage::jsVar('dotclear_htmlFontSize', $GLOBALS['core']->auth->user_prefs->interface->htmlfontsize) . "\n" . 
    145                 "</script>\n"; 
    146         } 
    147  
    148141        return $res; 
    149142    } 
  • plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.wysiwyg.js

    r3897 r3915  
    1 /*global jsToolBar, dotclear_htmlFontSize, chainHandler */ 
     1/*global jsToolBar, dotclear, chainHandler */ 
    22'use strict'; 
    33 
     
    184184    } 
    185185 
    186     if (typeof dotclear_htmlFontSize !== 'undefined') { 
    187       doc.documentElement.style.setProperty('--html-font-size', dotclear_htmlFontSize); 
     186    if (dotclear && dotclear.data && dotclear.data.htmlFontSize) { 
     187      doc.documentElement.style.setProperty('--html-font-size', dotclear.data.htmlFontSize); 
    188188    } 
    189189 
  • themes/berlin/_define.php

    r3874 r3915  
    1616    "Dotclear 2.7+ default theme", // Description 
    1717    "Dotclear Team",               // Author 
    18     '1.2',                         // Version 
     18    '1.3',                         // Version 
    1919    [                              // Properties 
    2020        'type'   => 'theme', 
  • themes/berlin/_public.php

    r3874 r3915  
    2323    public static function publicHeadContent() 
    2424    { 
    25         echo \dcUtils::jsVars([ 
    26             'dotclear_berlin_show_menu'  => __('Show menu'), 
    27             'dotclear_berlin_hide_menu'  => __('Hide menu'), 
    28             'dotclear_berlin_navigation' => __('Navigation') 
     25        echo 
     26        \dcUtils::jsLoad($GLOBALS['core']->blog->getPF('util.js')) . 
     27        \dcUtils::jsJson('dotclear_berlin', [ 
     28            'show_menu'  => __('Show menu'), 
     29            'hide_menu'  => __('Hide menu'), 
     30            'navigation' => __('Navigation') 
    2931        ]); 
    3032    } 
  • themes/berlin/js/berlin.js

    r3880 r3915  
    1 /*global $, dotclear_berlin_navigation, dotclear_berlin_show_menu, dotclear_berlin_hide_menu */ 
     1/*global $, getData */ 
    22'use strict'; 
     3 
     4const dotclear_berlin = getData('dotclear_berlin'); 
    35 
    46$('html').addClass('js'); 
    57// Show/Hide main menu 
    68$('.header__nav'). 
    7 before(`<button id="hamburger" type="button"><span class="visually-hidden">${dotclear_berlin_navigation}</span></button>`). 
     9before(`<button id="hamburger" type="button"><span class="visually-hidden">${dotclear_berlin.navigation}</span></button>`). 
    810toggle(); 
    911$('#hamburger').click(function() { 
     
    1214}); 
    1315// Show/Hide sidebar on small screens 
    14 $('#main').prepend(`<button id="offcanvas-on" type="button"><span class="visually-hidden">${dotclear_berlin_show_menu}</span></button>`); 
     16$('#main').prepend(`<button id="offcanvas-on" type="button"><span class="visually-hidden">${dotclear_berlin.show_menu}</span></button>`); 
    1517$('#offcanvas-on').click(function() { 
    16   const btn = $(`<button id="offcanvas-off" type="button"><span class="visually-hidden">${dotclear_berlin_hide_menu}</span></button>`); 
     18  const btn = $(`<button id="offcanvas-off" type="button"><span class="visually-hidden">${dotclear_berlin.hide_menu}</span></button>`); 
    1719  $('#wrapper').addClass('off-canvas'); 
    1820  $('#footer').addClass('off-canvas'); 
  • themes/berlin/style.css

    r3899 r3915  
    165165article, aside, details, figcaption, figure, footer, 
    166166header, hgroup, main, nav, section, summary { 
    167   display: block; } 
     167  display: block; 
     168  } 
    168169 
    169170audio, canvas, video { 
     
    644645  padding: 0; 
    645646  position: absolute; 
    646   width: 1px; } 
     647  width: 1px; 
     648  } 
    647649 
    648650.footer__widgets .widget { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map