Dotclear


Ignore:
Timestamp:
12/17/18 07:55:02 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Switching from inline JS variables to JSON script. dcLegacyEditor is coming

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/dcLegacyEditor/inc/dc.legacy.editor.behaviors.php

    r3915 r3945  
    2626        if (empty($editor) || $editor != 'dcLegacyEditor') {return;} 
    2727 
     28        $js = [ 
     29            'legacy_editor_context' => $context, 
     30            'legacy_editor_syntax' => $syntax, 
     31            'legacy_editor_tags_context' => [$context => $tags] 
     32        ]; 
     33 
    2834        return 
    2935        self::jsToolBar() . 
    30         dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/_post_editor.js')) . 
    31         '<script type="text/javascript">' . "\n" . 
    32         dcPage::jsVar('dotclear.legacy_editor_context', $context) . 
    33         dcPage::jsVar('dotclear.legacy_editor_syntax', $syntax) . 
    34         'dotclear.legacy_editor_tags_context = ' . sprintf('{%s:["%s"]};' . "\n", $context, implode('","', $tags)) . "\n" . 
    35             "</script>\n"; 
     36        dcPage::jsJson('legacy_editor_ctx', $js) . 
     37        dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/_post_editor.js')); 
    3638    } 
    3739 
     
    5961    protected static function jsToolBar() 
    6062    { 
     63        $rtl = l10n::getTextDirection($GLOBALS['_lang']) == 'rtl' ? 'direction: rtl;' : ''; 
     64        $css = <<<EOT 
     65body { 
     66    color: #000; 
     67    background: #f9f9f9; 
     68    margin: 0; 
     69    padding: 2px; 
     70    border: none; 
     71    $rtl 
     72} 
     73code { 
     74    color: #666; 
     75    font-weight: bold; 
     76} 
     77body > p:first-child { 
     78    margin-top: 0; 
     79} 
     80EOT; 
     81        $js = [ 
     82            'dialog_url'            => 'popup.php', 
     83            'iframe_css'            => $css, 
     84            'base_url'              => $GLOBALS['core']->blog->host, 
     85            'switcher_visual_title' => __('visual'), 
     86            'switcher_source_title' => __('source'), 
     87            'legend_msg'            => __('You can use the following shortcuts to format your text.'), 
     88            'elements'              => [ 
     89                    'blocks' => ['options' => [ 
     90                        'none' => __('-- none --'), 
     91                        'nonebis' => __('-- block format --'), 
     92                        'p' => __('Paragraph'), 
     93                        'h1' => __('Level 1 header'), 
     94                        'h2' => __('Level 2 header'), 
     95                        'h3' => __('Level 3 header'), 
     96                        'h4' => __('Level 4 header'), 
     97                        'h5' => __('Level 5 header'), 
     98                        'h6' => __('Level 6 header'), 
     99                    ]], 
     100 
     101                    'strong' => ['title' => __('Strong emphasis')], 
     102                    'em' => ['title' => __('Emphasis')], 
     103                    'ins' => ['title' => __('Inserted')], 
     104                    'del' => ['title' => __('Deleted')], 
     105                    'quote' => ['title' => __('Inline quote')], 
     106                    'code' => ['title' => __('Code')], 
     107                    'mark' => ['title' => __('Mark')], 
     108                    'br' => ['title' => __('Line break')], 
     109                    'blockquote' => ['title' => __('Blockquote')], 
     110                    'pre' => ['title' => __('Preformated text')], 
     111                    'ul' => ['title' => __('Unordered list')], 
     112                    'ol' => ['title' => __('Ordered list')], 
     113 
     114                    'link' => [ 
     115                        'title' => __('Link'), 
     116                        'accesskey' => __('l'), 
     117                        'href_prompt' => __('URL?'), 
     118                        'hreflang_prompt' => __('Language?') 
     119                    ], 
     120 
     121                    'img' => [ 
     122                        'title' => __('External image'), 
     123                        'src_prompt' => __('URL?') 
     124                    ], 
     125 
     126                    'img_select' => [ 
     127                        'title' => __('Media chooser'), 
     128                        'accesskey' => __('m') 
     129                    ], 
     130 
     131                    'post_link' => ['title' => __('Link to an entry')], 
     132                    'removeFormat' => ['title' => __('Remove text formating')] 
     133            ], 
     134            'toolbar_bottom' => (boolean) isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('toolbar_bottom') 
     135        ]; 
     136        if (!$GLOBALS['core']->auth->check('media,media_admin', $GLOBALS['core']->blog->id)) { 
     137            $js['elements']['img_select']['disabled'] = true; 
     138        } 
     139 
    61140        $res = 
     141        dcPage::jsJson('legacy_editor', $js) . 
    62142        dcPage::cssLoad(dcPage::getPF('dcLegacyEditor/css/jsToolBar/jsToolBar.css')) . 
    63143        dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.js')); 
     
    69149        $res .= 
    70150        dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js')) . 
    71         '<script type="text/javascript">' . "\n" . 
    72         "jsToolBar.prototype.dialog_url = 'popup.php'; " . "\n" . 
    73         "jsToolBar.prototype.iframe_css = '" . 
    74         'body {' . 
    75         '   color: #000;' . 
    76         '   background: #f9f9f9;' . 
    77         '   margin: 0;' . 
    78         '   padding: 2px;' . 
    79         '   border: none;' . 
    80         (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl' ? ' direction: rtl;' : '') . 
    81         '}' . 
    82         'code {' . 
    83         '   color: #666;' . 
    84         '   font-weight: bold;' . 
    85         '}' . 
    86         'body > p:first-child {' . 
    87         '   margin-top: 0;' . 
    88         '}' . 
    89         "'; " . "\n" . 
    90         "jsToolBar.prototype.base_url = '" . html::escapeJS($GLOBALS['core']->blog->host) . "'; " . "\n" . 
    91         "jsToolBar.prototype.switcher_visual_title = '" . html::escapeJS(__('visual')) . "'; " . "\n" . 
    92         "jsToolBar.prototype.switcher_source_title = '" . html::escapeJS(__('source')) . "'; " . "\n" . 
    93         "jsToolBar.prototype.legend_msg = '" . 
    94         html::escapeJS(__('You can use the following shortcuts to format your text.')) . "'; " . "\n" . 
    95         "jsToolBar.prototype.elements.blocks.options.none = '" . html::escapeJS(__('-- none --')) . "'; " . "\n" . 
    96         "jsToolBar.prototype.elements.blocks.options.nonebis = '" . html::escapeJS(__('-- block format --')) . "'; " . "\n" . 
    97         "jsToolBar.prototype.elements.blocks.options.p = '" . html::escapeJS(__('Paragraph')) . "'; " . "\n" . 
    98         "jsToolBar.prototype.elements.blocks.options.h1 = '" . html::escapeJS(__('Level 1 header')) . "'; " . "\n" . 
    99         "jsToolBar.prototype.elements.blocks.options.h2 = '" . html::escapeJS(__('Level 2 header')) . "'; " . "\n" . 
    100         "jsToolBar.prototype.elements.blocks.options.h3 = '" . html::escapeJS(__('Level 3 header')) . "'; " . "\n" . 
    101         "jsToolBar.prototype.elements.blocks.options.h4 = '" . html::escapeJS(__('Level 4 header')) . "'; " . "\n" . 
    102         "jsToolBar.prototype.elements.blocks.options.h5 = '" . html::escapeJS(__('Level 5 header')) . "'; " . "\n" . 
    103         "jsToolBar.prototype.elements.blocks.options.h6 = '" . html::escapeJS(__('Level 6 header')) . "'; " . "\n" . 
    104         "jsToolBar.prototype.elements.strong.title = '" . html::escapeJS(__('Strong emphasis')) . "'; " . "\n" . 
    105         "jsToolBar.prototype.elements.em.title = '" . html::escapeJS(__('Emphasis')) . "'; " . "\n" . 
    106         "jsToolBar.prototype.elements.ins.title = '" . html::escapeJS(__('Inserted')) . "'; " . "\n" . 
    107         "jsToolBar.prototype.elements.del.title = '" . html::escapeJS(__('Deleted')) . "'; " . "\n" . 
    108         "jsToolBar.prototype.elements.quote.title = '" . html::escapeJS(__('Inline quote')) . "'; " . "\n" . 
    109         "jsToolBar.prototype.elements.code.title = '" . html::escapeJS(__('Code')) . "'; " . "\n" . 
    110         "jsToolBar.prototype.elements.mark.title = '" . html::escapeJS(__('Mark')) . "'; " . "\n" . 
    111         "jsToolBar.prototype.elements.br.title = '" . html::escapeJS(__('Line break')) . "'; " . "\n" . 
    112         "jsToolBar.prototype.elements.blockquote.title = '" . html::escapeJS(__('Blockquote')) . "'; " . "\n" . 
    113         "jsToolBar.prototype.elements.pre.title = '" . html::escapeJS(__('Preformated text')) . "'; " . "\n" . 
    114         "jsToolBar.prototype.elements.ul.title = '" . html::escapeJS(__('Unordered list')) . "'; " . "\n" . 
    115         "jsToolBar.prototype.elements.ol.title = '" . html::escapeJS(__('Ordered list')) . "'; " . "\n" . 
    116  
    117         "jsToolBar.prototype.elements.link.title = '" . html::escapeJS(__('Link')) . "'; " . "\n" . 
    118         "jsToolBar.prototype.elements.link.accesskey = '" . html::escapeJS(__('l')) . "'; " . "\n" . 
    119         "jsToolBar.prototype.elements.link.href_prompt = '" . html::escapeJS(__('URL?')) . "'; " . "\n" . 
    120         "jsToolBar.prototype.elements.link.hreflang_prompt = '" . html::escapeJS(__('Language?')) . "'; " . "\n" . 
    121  
    122         "jsToolBar.prototype.elements.img.title = '" . html::escapeJS(__('External image')) . "'; " . "\n" . 
    123         "jsToolBar.prototype.elements.img.src_prompt = '" . html::escapeJS(__('URL?')) . "'; " . "\n" . 
    124  
    125         "jsToolBar.prototype.elements.img_select.title = '" . html::escapeJS(__('Media chooser')) . "'; " . "\n" . 
    126         "jsToolBar.prototype.elements.img_select.accesskey = '" . html::escapeJS(__('m')) . "'; " . "\n" . 
    127         "jsToolBar.prototype.elements.post_link.title = '" . html::escapeJS(__('Link to an entry')) . "'; " . "\n" . 
    128         "jsToolBar.prototype.elements.removeFormat = jsToolBar.prototype.elements.removeFormat || {}; " . "\n" . 
    129         "jsToolBar.prototype.elements.removeFormat.title = '" . html::escapeJS(__('Remove text formating')) . "'; " . "\n"; 
    130  
    131         if (!$GLOBALS['core']->auth->check('media,media_admin', $GLOBALS['core']->blog->id)) { 
    132             $res .= "jsToolBar.prototype.elements.img_select.disabled = true;\n"; 
    133         } 
    134  
    135         $res .= "jsToolBar.prototype.toolbar_bottom = " . 
    136             (isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('toolbar_bottom') ? 'true' : 'false') . ";\n"; 
    137  
    138         $res .= 
    139             "</script>\n"; 
     151        dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.config.js')); 
    140152 
    141153        return $res; 
Note: See TracChangeset for help on using the changeset viewer.

Sites map