Dotclear

Changeset 3980:df625feec28c for plugins


Ignore:
Timestamp:
06/24/19 14:29:57 (6 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Switching from inline JS variables to JSON script, theme editor plugin

Location:
plugins/themeEditor
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • plugins/themeEditor/_admin.php

    r3874 r3980  
    7070            form::combo('colorsyntax_theme', $themes_combo, 
    7171                [ 
    72                     'default'    => $core->auth->user_prefs->interface->colorsyntax_theme, 
    73                     'extra_html' => 'onchange="selectTheme()"']) . 
     72                    'default' => $core->auth->user_prefs->interface->colorsyntax_theme 
     73                ]) . 
    7474                '</p>'; 
    7575        } else { 
     
    9797}</textarea>'; 
    9898        echo 
    99             '<script> 
    100             var input = document.getElementById("colorsyntax_theme"); 
    101             var theme = input.options[input.selectedIndex].textContent; 
    102             var editor = CodeMirror.fromTextArea(document.getElementById("codemirror"), { 
    103                 mode: "javascript", 
    104                 tabMode: "indent", 
    105                 lineWrapping: 1, 
    106                 lineNumbers: 1, 
    107                 matchBrackets: 1, 
    108                 autoCloseBrackets: 1, 
    109                 theme: "' . ($core->auth->user_prefs->interface->colorsyntax_theme != '' ? $core->auth->user_prefs->interface->colorsyntax_theme : 'default') . '" 
    110             }); 
    111             function selectTheme() { 
    112                 var input = document.getElementById("colorsyntax_theme"); 
    113                 var theme = input.options[input.selectedIndex].value; 
    114                 if (theme == "") theme = "default"; 
    115                 editor.setOption("theme", theme); 
    116                 editor.refresh(); 
    117             } 
    118         </script>'; 
     99        dcPage::jsJson('theme_editor_current', ['theme' => $core->auth->user_prefs->interface->colorsyntax_theme != '' ? $core->auth->user_prefs->interface->colorsyntax_theme : 'default']) . 
     100        dcPage::jsLoad(dcPage::getPF('themeEditor/js/theme.js')); 
    119101        echo '</div>'; 
    120102        echo '</div>'; 
  • plugins/themeEditor/index.php

    r3874 r3980  
    6666    <title><?php echo __('Edit theme files'); ?></title> 
    6767    <?php 
    68 echo dcPage::jsVars([ 
    69     'dotclear.msg.saving_document'    => __("Saving document..."), 
    70     'dotclear.msg.document_saved'     => __("Document saved"), 
    71     'dotclear.msg.error_occurred'     => __("An error occurred:"), 
    72     'dotclear.msg.confirm_reset_file' => __("Are you sure you want to reset this file?") 
     68if ($user_ui_colorsyntax) { 
     69    echo dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => $user_ui_colorsyntax]); 
     70} 
     71echo dcPage::jsJson('theme_editor_msg', [ 
     72    'saving_document'    => __("Saving document..."), 
     73    'document_saved'     => __("Document saved"), 
     74    'error_occurred'     => __("An error occurred:"), 
     75    'confirm_reset_file' => __("Are you sure you want to reset this file?") 
    7376]) . 
    74 dcPage::jsConfirmClose('file-form') . 
    75 dcPage::jsLoad(dcPage::getPF('themeEditor/js/script.js')); 
     77dcPage::jsLoad(dcPage::getPF('themeEditor/js/script.js')) . 
     78dcPage::jsConfirmClose('file-form') ; 
    7679if ($user_ui_colorsyntax) { 
    77     echo dcPage::jsVars(['dotclear.colorsyntax' => $user_ui_colorsyntax]); 
    7880    echo dcPage::jsLoadCodeMirror($user_ui_colorsyntax_theme); 
    7981} 
     
    135137            (!empty($_REQUEST['js']) ? "javascript" : 
    136138                (!empty($_REQUEST['po']) ? "text/plain" : "text/html"))); 
    137         echo 
    138             '<script type="text/javascript"> 
    139             window.CodeMirror.defineMode("dotclear", function(config) { 
    140                 return CodeMirror.multiplexingMode( 
    141                     CodeMirror.getMode(config, "' . $editorMode . '"), 
    142                     {open: "{{tpl:", close: "}}", 
    143                      mode: CodeMirror.getMode(config, "text/plain"), 
    144                      delimStyle: "delimit"}, 
    145                     {open: "<tpl:", close: ">", 
    146                      mode: CodeMirror.getMode(config, "text/plain"), 
    147                      delimStyle: "delimit"}, 
    148                     {open: "</tpl:", close: ">", 
    149                      mode: CodeMirror.getMode(config, "text/plain"), 
    150                      delimStyle: "delimit"} 
    151                     ); 
    152             }); 
    153         </script>'; 
     139        echo dcPage::jsJson('theme_editor_mode', ['mode' => $editorMode]); 
     140        echo dcPage::jsLoad(dcPage::getPF('themeEditor/js/mode.js')); 
    154141        echo dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', $user_ui_colorsyntax_theme); 
    155142    } 
  • plugins/themeEditor/js/script.js

    r3880 r3980  
    1 /*global $, dotclear, editor, confirmClosePage */ 
     1/*global $, dotclear, editor, confirmClosePage, getData */ 
    22'use strict'; 
     3 
     4// Get locales and setting 
     5Object.assign(dotclear.msg, getData('theme_editor_msg')); 
     6Object.assign(dotclear, getData('dotclear_colorsyntax')); 
    37 
    48$(function() { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map