Plugin Directory

Changeset 2132610


Ignore:
Timestamp:
08/02/2019 08:35:03 AM (6 years ago)
Author:
radovank
Message:

added JS dictionary object

Location:
template-dictionary/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • template-dictionary/trunk/readme.txt

    r2115677 r2132610  
    44Requires at least: 4.5
    55Tested up to: 5.2.2
    6 Stable tag: 1.5
     6Stable tag: 1.6
    77License: GPL2
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5151If your site is not multilingual, there is only one available language – the default language.
    5252
     53= Use JS object =
     54To generate JavaScript dictionary object, you need to define `TMPL_DICT_JS_VAR_NAME` constant. Add to `wp_config.php`:
     55
     56`define( 'TMPL_DICT_JS_VAR_NAME', 'dict' );`
     57
     58Then you can use it in JS:
     59
     60`$('#some-element').text( dict.the_code );`
     61
    5362== Screenshots ==
    5463
     
    6170
    6271== Changelog ==
     72= 1.6 =
     73* Added method to get whole dictionary array.
     74* Added JS dictionary object.
    6375
    6476= 1.5 =
  • template-dictionary/trunk/template-dictionary.php

    r1830393 r2132610  
    33 * Plugin Name: Template Dictionary
    44 * Description: A plugin for developers which provides template variables dictionary editable in backend.
    5  * Version:     1.5
     5 * Version:     1.6
    66 * Author:      Radovan Kneblík
    77 * License:     GPL2
     
    2424     * @var string
    2525     */
    26     private $version = '1.4';
     26    private $version = '1.6';
    2727
    2828    /**
     
    122122        add_action( 'plugins_loaded', array( $this, 'load_language' ), 5 );
    123123        add_action( 'plugins_loaded', array( $this, 'load' ), 9 );
     124        if( defined( 'TMPL_DICT_JS_VAR_NAME' ) ){
     125            add_action( 'wp_head', array( $this, 'js_dictionary' ) );
     126        }
    124127
    125128        add_shortcode( 'tmpl_dict', array( $this, 'shortcode' ) );
     
    196199     * Get the plugin's database table(s).
    197200     * @param string|null $key
    198      * @return string
     201     * @return string|array
    199202     */
    200203    public function db_tables( $key = null ){
     
    337340
    338341    /**
     342     * Get the whole dictionary array.
     343     * @return array
     344     */
     345    public function get_dictionary(){
     346        return $this->dictionary;
     347    }
     348
     349    /**
    339350     * The shortcode function.
    340351     */
     
    365376            return $value;
    366377        }
     378    }
     379
     380    /**
     381     * Create JS object.
     382     */
     383    public function js_dictionary(){ ?>
     384<script type="text/javascript">
     385/* <![CDATA[ */
     386var <?php echo TMPL_DICT_JS_VAR_NAME; ?> = <?php echo json_encode( $this->get_dictionary() ); ?>;
     387/* ]]> */
     388</script><?php
    367389    }
    368390
Note: See TracChangeset for help on using the changeset viewer.