Dotclear

Changeset 3930:5007b8ff2be4


Ignore:
Timestamp:
11/13/18 17:14:28 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Switching from inline JS variables to JSON script. Common js vars and msg

Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • admin/js/common.js

    r3927 r3930  
    1 /*global $, jQuery */ 
    2 /*exported chainHandler, getData */ 
     1/*global $, jQuery, getData */ 
     2/*exported chainHandler */ 
    33'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 } 
    214 
    225/* Get PreInit JSON data */ 
     
    570553  dotclear.data = dotclear_init; 
    571554  // Get other DATA 
    572   Object.assign(dotclear.data, getData('dotclear')); 
     555  Object.assign(dotclear, getData('dotclear')); 
     556  Object.assign(dotclear.msg, getData('dotclear_msg')); 
    573557 
    574558  // remove class no-js from html tag; cf style/default.css for examples 
  • admin/js/date-picker.js

    r3922 r3930  
     1/*global getData */ 
     2/*exported datePicker */ 
    13'use strict'; 
    24 
  • inc/admin/lib.dc.page.php

    r3929 r3930  
    700700        $core = self::getCore(); 
    701701 
    702         $mute_or_no = ''; 
    703         if (empty($core->blog) || $core->blog->settings->system->jquery_migrate_mute) { 
    704             $mute_or_no .= 
    705                 '<script type="text/javascript">' . "\n" . 
    706                 'jQuery.migrateMute = true;' . "\n" . 
    707                 "</script>\n"; 
    708         } 
     702        $js = [ 
     703            'nonce'               => $core->getNonce(), 
     704 
     705            'img_plus_src'        => 'images/expand.png', 
     706            'img_plus_txt'        => '►', 
     707            'img_plus_alt'        => __('uncover'), 
     708 
     709            'img_minus_src'       => 'images/hide.png', 
     710            'img_minus_txt'       => '▼', 
     711            'img_minus_alt'       => __('hide'), 
     712 
     713            'img_menu_on'         => 'images/menu_on.png', 
     714            'img_menu_off'        => 'images/menu_off.png', 
     715 
     716            'img_plus_theme_src'  => 'images/plus-theme.png', 
     717            'img_plus_theme_txt'  => '►', 
     718            'img_plus_theme_alt'  => __('uncover'), 
     719 
     720            'img_minus_theme_src' => 'images/minus-theme.png', 
     721            'img_minus_theme_txt' => '▼', 
     722            'img_minus_theme_alt' => __('hide') 
     723        ]; 
     724 
     725        $js_msg = [ 
     726            'help'                                 => __('Need help?'), 
     727            'new_window'                           => __('new window'), 
     728            'help_hide'                            => __('Hide'), 
     729            'to_select'                            => __('Select:'), 
     730            'no_selection'                         => __('no selection'), 
     731            'select_all'                           => __('select all'), 
     732            'invert_sel'                           => __('Invert selection'), 
     733            'website'                              => __('Web site:'), 
     734            'email'                                => __('Email:'), 
     735            'ip_address'                           => __('IP address:'), 
     736            'error'                                => __('Error:'), 
     737            'entry_created'                        => __('Entry has been successfully created.'), 
     738            'edit_entry'                           => __('Edit entry'), 
     739            'view_entry'                           => __('view entry'), 
     740            'confirm_delete_posts'                 => __("Are you sure you want to delete selected entries (%s)?"), 
     741            'confirm_delete_medias'                => __("Are you sure you want to delete selected medias (%d)?"), 
     742            'confirm_delete_categories'            => __("Are you sure you want to delete selected categories (%s)?"), 
     743            'confirm_delete_post'                  => __("Are you sure you want to delete this entry?"), 
     744            'click_to_unlock'                      => __("Click here to unlock the field"), 
     745            'confirm_spam_delete'                  => __('Are you sure you want to delete all spams?'), 
     746            'confirm_delete_comments'              => __('Are you sure you want to delete selected comments (%s)?'), 
     747            'confirm_delete_comment'               => __('Are you sure you want to delete this comment?'), 
     748            'cannot_delete_users'                  => __('Users with posts cannot be deleted.'), 
     749            'confirm_delete_user'                  => __('Are you sure you want to delete selected users (%s)?'), 
     750            'confirm_delete_blog'                  => __('Are you sure you want to delete selected blogs (%s)?'), 
     751            'confirm_delete_category'              => __('Are you sure you want to delete category "%s"?'), 
     752            'confirm_reorder_categories'           => __('Are you sure you want to reorder all categories?'), 
     753            'confirm_delete_media'                 => __('Are you sure you want to remove media "%s"?'), 
     754            'confirm_delete_directory'             => __('Are you sure you want to remove directory "%s"?'), 
     755            'confirm_extract_current'              => __('Are you sure you want to extract archive in current directory?'), 
     756            'confirm_remove_attachment'            => __('Are you sure you want to remove attachment "%s"?'), 
     757            'confirm_delete_lang'                  => __('Are you sure you want to delete "%s" language?'), 
     758            'confirm_delete_plugin'                => __('Are you sure you want to delete "%s" plugin?'), 
     759            'confirm_delete_plugins'               => __('Are you sure you want to delete selected plugins?'), 
     760            'use_this_theme'                       => __('Use this theme'), 
     761            'remove_this_theme'                    => __('Remove this theme'), 
     762            'confirm_delete_theme'                 => __('Are you sure you want to delete "%s" theme?'), 
     763            'confirm_delete_themes'                => __('Are you sure you want to delete selected themes?'), 
     764            'confirm_delete_backup'                => __('Are you sure you want to delete this backup?'), 
     765            'confirm_revert_backup'                => __('Are you sure you want to revert to this backup?'), 
     766            'zip_file_content'                     => __('Zip file content'), 
     767            'xhtml_validator'                      => __('XHTML markup validator'), 
     768            'xhtml_valid'                          => __('XHTML content is valid.'), 
     769            'xhtml_not_valid'                      => __('There are XHTML markup errors.'), 
     770            'warning_validate_no_save_content'     => __('Attention: an audit of a content not yet registered.'), 
     771            'confirm_change_post_format'           => __('You have unsaved changes. Switch post format will loose these changes. Proceed anyway?'), 
     772            'confirm_change_post_format_noconvert' => __("Warning: post format change will not convert existing content. You will need to apply new format by yourself. Proceed anyway?"), 
     773            'load_enhanced_uploader'               => __('Loading enhanced uploader, please wait.'), 
     774 
     775            'module_author'                        => __('Author:'), 
     776            'module_details'                       => __('Details'), 
     777            'module_support'                       => __('Support'), 
     778            'module_help'                          => __('Help:'), 
     779            'module_section'                       => __('Section:'), 
     780            'module_tags'                          => __('Tags:'), 
     781 
     782            'close_notice'                         => __('Hide this notice') 
     783        ]; 
    709784 
    710785        return 
     786        self::jsLoad('js/prepend.js') . 
    711787        self::jsLoad('js/jquery/jquery.js') . 
    712         $mute_or_no . 
     788        self::jsJson('dotclear_jquery', [ 
     789            'mute' => (empty($core->blog) || $core->blog->settings->system->jquery_migrate_mute) 
     790        ]) . 
     791        self::jsLoad('js/jquery-mute.js') . 
    713792        self::jsLoad('js/jquery/jquery-migrate.js') . 
    714793        self::jsLoad('js/jquery/jquery.biscuit.js') . 
     794 
     795        self::jsJson('dotclear', $js) . 
     796        self::jsJson('dotclear_msg', $js_msg) . 
     797 
    715798        self::jsLoad('js/common.js') . 
    716799        self::jsLoad('js/services.js') . 
    717         self::jsLoad('js/prelude.js') . 
    718  
    719         '<script type="text/javascript">' . "\n" . 
    720         'jsToolBar = {}, jsToolBar.prototype = { elements : {} };' . "\n" . 
    721  
    722         self::jsVar('dotclear.nonce', $core->getNonce()) . 
    723  
    724         self::jsVar('dotclear.img_plus_src', 'images/expand.png') . 
    725         self::jsVar('dotclear.img_plus_txt', '►') . 
    726         self::jsVar('dotclear.img_plus_alt', __('uncover')) . 
    727         self::jsVar('dotclear.img_minus_src', 'images/hide.png') . 
    728         self::jsVar('dotclear.img_minus_txt', '▼') . 
    729         self::jsVar('dotclear.img_minus_alt', __('hide')) . 
    730         self::jsVar('dotclear.img_menu_on', 'images/menu_on.png') . 
    731         self::jsVar('dotclear.img_menu_off', 'images/menu_off.png') . 
    732  
    733         self::jsVar('dotclear.img_plus_theme_src', 'images/plus-theme.png') . 
    734         self::jsVar('dotclear.img_plus_theme_txt', '►') . 
    735         self::jsVar('dotclear.img_plus_theme_alt', __('uncover')) . 
    736         self::jsVar('dotclear.img_minus_theme_src', 'images/minus-theme.png') . 
    737         self::jsVar('dotclear.img_minus_theme_txt', '▼') . 
    738         self::jsVar('dotclear.img_minus_theme_alt', __('hide')) . 
    739  
    740         self::jsVar('dotclear.msg.help', 
    741             __('Need help?')) . 
    742         self::jsVar('dotclear.msg.new_window', 
    743             __('new window')) . 
    744         self::jsVar('dotclear.msg.help_hide', 
    745             __('Hide')) . 
    746         self::jsVar('dotclear.msg.to_select', 
    747             __('Select:')) . 
    748         self::jsVar('dotclear.msg.no_selection', 
    749             __('no selection')) . 
    750         self::jsVar('dotclear.msg.select_all', 
    751             __('select all')) . 
    752         self::jsVar('dotclear.msg.invert_sel', 
    753             __('Invert selection')) . 
    754         self::jsVar('dotclear.msg.website', 
    755             __('Web site:')) . 
    756         self::jsVar('dotclear.msg.email', 
    757             __('Email:')) . 
    758         self::jsVar('dotclear.msg.ip_address', 
    759             __('IP address:')) . 
    760         self::jsVar('dotclear.msg.error', 
    761             __('Error:')) . 
    762         self::jsVar('dotclear.msg.entry_created', 
    763             __('Entry has been successfully created.')) . 
    764         self::jsVar('dotclear.msg.edit_entry', 
    765             __('Edit entry')) . 
    766         self::jsVar('dotclear.msg.view_entry', 
    767             __('view entry')) . 
    768         self::jsVar('dotclear.msg.confirm_delete_posts', 
    769             __("Are you sure you want to delete selected entries (%s)?")) . 
    770         self::jsVar('dotclear.msg.confirm_delete_medias', 
    771             __("Are you sure you want to delete selected medias (%d)?")) . 
    772         self::jsVar('dotclear.msg.confirm_delete_categories', 
    773             __("Are you sure you want to delete selected categories (%s)?")) . 
    774         self::jsVar('dotclear.msg.confirm_delete_post', 
    775             __("Are you sure you want to delete this entry?")) . 
    776         self::jsVar('dotclear.msg.click_to_unlock', 
    777             __("Click here to unlock the field")) . 
    778         self::jsVar('dotclear.msg.confirm_spam_delete', 
    779             __('Are you sure you want to delete all spams?')) . 
    780         self::jsVar('dotclear.msg.confirm_delete_comments', 
    781             __('Are you sure you want to delete selected comments (%s)?')) . 
    782         self::jsVar('dotclear.msg.confirm_delete_comment', 
    783             __('Are you sure you want to delete this comment?')) . 
    784         self::jsVar('dotclear.msg.cannot_delete_users', 
    785             __('Users with posts cannot be deleted.')) . 
    786         self::jsVar('dotclear.msg.confirm_delete_user', 
    787             __('Are you sure you want to delete selected users (%s)?')) . 
    788         self::jsVar('dotclear.msg.confirm_delete_blog', 
    789             __('Are you sure you want to delete selected blogs (%s)?')) . 
    790         self::jsVar('dotclear.msg.confirm_delete_category', 
    791             __('Are you sure you want to delete category "%s"?')) . 
    792         self::jsVar('dotclear.msg.confirm_reorder_categories', 
    793             __('Are you sure you want to reorder all categories?')) . 
    794         self::jsVar('dotclear.msg.confirm_delete_media', 
    795             __('Are you sure you want to remove media "%s"?')) . 
    796         self::jsVar('dotclear.msg.confirm_delete_directory', 
    797             __('Are you sure you want to remove directory "%s"?')) . 
    798         self::jsVar('dotclear.msg.confirm_extract_current', 
    799             __('Are you sure you want to extract archive in current directory?')) . 
    800         self::jsVar('dotclear.msg.confirm_remove_attachment', 
    801             __('Are you sure you want to remove attachment "%s"?')) . 
    802         self::jsVar('dotclear.msg.confirm_delete_lang', 
    803             __('Are you sure you want to delete "%s" language?')) . 
    804         self::jsVar('dotclear.msg.confirm_delete_plugin', 
    805             __('Are you sure you want to delete "%s" plugin?')) . 
    806         self::jsVar('dotclear.msg.confirm_delete_plugins', 
    807             __('Are you sure you want to delete selected plugins?')) . 
    808         self::jsVar('dotclear.msg.use_this_theme', 
    809             __('Use this theme')) . 
    810         self::jsVar('dotclear.msg.remove_this_theme', 
    811             __('Remove this theme')) . 
    812         self::jsVar('dotclear.msg.confirm_delete_theme', 
    813             __('Are you sure you want to delete "%s" theme?')) . 
    814         self::jsVar('dotclear.msg.confirm_delete_themes', 
    815             __('Are you sure you want to delete selected themes?')) . 
    816         self::jsVar('dotclear.msg.confirm_delete_backup', 
    817             __('Are you sure you want to delete this backup?')) . 
    818         self::jsVar('dotclear.msg.confirm_revert_backup', 
    819             __('Are you sure you want to revert to this backup?')) . 
    820         self::jsVar('dotclear.msg.zip_file_content', 
    821             __('Zip file content')) . 
    822         self::jsVar('dotclear.msg.xhtml_validator', 
    823             __('XHTML markup validator')) . 
    824         self::jsVar('dotclear.msg.xhtml_valid', 
    825             __('XHTML content is valid.')) . 
    826         self::jsVar('dotclear.msg.xhtml_not_valid', 
    827             __('There are XHTML markup errors.')) . 
    828         self::jsVar('dotclear.msg.warning_validate_no_save_content', 
    829             __('Attention: an audit of a content not yet registered.')) . 
    830         self::jsVar('dotclear.msg.confirm_change_post_format', 
    831             __('You have unsaved changes. Switch post format will loose these changes. Proceed anyway?')) . 
    832         self::jsVar('dotclear.msg.confirm_change_post_format_noconvert', 
    833             __("Warning: post format change will not convert existing content. You will need to apply new format by yourself. Proceed anyway?")) . 
    834         self::jsVar('dotclear.msg.load_enhanced_uploader', 
    835             __('Loading enhanced uploader, please wait.')) . 
    836  
    837         self::jsVar('dotclear.msg.module_author', 
    838             __('Author:')) . 
    839         self::jsVar('dotclear.msg.module_details', 
    840             __('Details')) . 
    841         self::jsVar('dotclear.msg.module_support', 
    842             __('Support')) . 
    843         self::jsVar('dotclear.msg.module_help', 
    844             __('Help:')) . 
    845         self::jsVar('dotclear.msg.module_section', 
    846             __('Section:')) . 
    847         self::jsVar('dotclear.msg.module_tags', 
    848             __('Tags:')) . 
    849  
    850         self::jsVar('dotclear.msg.close_notice', 
    851             __('Hide this notice')) . 
    852  
    853             "\n" . 
    854             "</script>\n"; 
     800        self::jsLoad('js/prelude.js'); 
    855801    } 
    856802 
     
    867813        $js = [ 
    868814            'prompt' => __('You have unsaved changes.'), 
    869             'forms' => $args 
     815            'forms'  => $args 
    870816        ]; 
    871817        return 
Note: See TracChangeset for help on using the changeset viewer.

Sites map