WordPress.org

Make WordPress Core

Changeset 4968


Ignore:
Timestamp:
03/06/2007 12:39:46 AM (11 years ago)
Author:
ryan
Message:

JS localization from mdawaffe. fixes #3911

Location:
trunk/wp-includes
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/list-manipulation.js

    r4966 r4968  
    1 <?php @require_once('../../wp-config.php'); cache_javascript_headers(); ?>
    2 addLoadEvent(function(){theList=new listMan();});
    3 function deleteSomething(what,id,message,obj){if(!obj)obj=theList;if(!message)message="<?php printf(js_escape(__('Are you sure you want to delete this %s?')),"'+what+'"); ?>";if(confirm(message))return obj.ajaxDelete(what,id);else return false;}
    4 function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);}
     1addLoadEvent( function() {
     2    if ( 'undefined' != typeof listManL10n )
     3        Object.extend(listMan.prototype, listManL10n);
     4    theList = new listMan();
     5} );
     6
     7function deleteSomething( what, id, message, obj ) {
     8    if ( !obj )
     9        obj=theList;
     10    if ( !message )
     11        message = obj.delText.replace(/%/g, what);
     12    if( confirm(message) )
     13        return obj.ajaxDelete( what, id );
     14    else return false;
     15}
     16
     17function dimSomething( what, id, dimClass, obj ) {
     18    if ( !obj )
     19        obj = theList;
     20    return obj.ajaxDimmer(what,id,dimClass);
     21}
    522
    623var listMan = Class.create();
     
    1936    dataStore: null,
    2037    formStore: null,
     38
     39    jumpText: 'Jump to new item',
     40    delText: 'Are you sure you want to delete this %s?',
    2141
    2242    initialize: function(theListId) {
     
    5474                        showLinkMessage += m;
    5575                    else
    56                         showLinkMessage += "<a href='#" + what + '-' + id + "'><?php echo js_escape(__('Jump to new item')); ?>";
     76                        showLinkMessage += "<a href='#" + what + '-' + id + "'>" + tempObj.jumpText + "</a>";
    5777                });
    5878                if ( tempObj.showLink && showLinkMessage )
     
    128148        var id = this.topAdder ? this.theList.firstChild.id : this.theList.lastChild.id;
    129149        if ( this.alt )
    130             if ( this.theList.childNodes.length % 2 )
     150            if ( ( this.theList.childNodes.length + this.altOffset ) % 2 )
    131151                Element.addClassName($(id),this.alt);
    132152        Fat.fade_element(id);
  • trunk/wp-includes/script-loader.php

    r4948 r4968  
    2222        $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116');
    2323        $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '20070118');
    24         $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '20070118');
     24        $this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070305');
     25        $this->localize( 'listman', 'listManL10n', array(
     26            'jumpText' => __('Jump to new item'),
     27            'delText' => __('Are you sure you want to delete this %s?')
     28        ) );
    2529        $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.7.0');
    2630        $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.7.0');
     
    8488                    $src = apply_filters( 'script_loader_src', $src );
    8589                    echo "<script type='text/javascript' src='$src'></script>\n";
     90                    $this->print_scripts_l10n( $handle );
    8691                }
    8792                $this->printed[] = $handle;
     
    9095    }
    9196
     97    function print_scripts_l10n( $handle ) {
     98        if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) )
     99            return;
     100
     101        $object_name = $this->scripts[$handle]->l10n_object;
     102
     103        echo "<script type='text/javascript'>\n";
     104        echo "/* <![CDATA[ */\n";
     105        echo "\t$object_name = {\n";
     106        $eol = '';
     107        foreach ( $this->scripts[$handle]->l10n as $var => $val ) {
     108            echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
     109            $eol = ",\n";
     110        }
     111        echo "\n\t}\n";
     112        echo "/* ]]> */\n";
     113        echo "</script>\n";
     114    }
    92115
    93116    /**
     
    141164    }
    142165
     166    /**
     167     * Localizes a script
     168     *
     169     * Localizes only if script has already been added
     170     *
     171     * @param string handle Script name
     172     * @param string object_name Name of JS object to hold l10n info
     173     * @param array l10n Array of JS var name => localized string
     174     * @return bool Successful localization
     175     */
     176    function localize( $handle, $object_name, $l10n ) {
     177        if ( !isset($this->scripts[$handle]) )
     178            return false;
     179        return $this->scripts[$handle]->localize( $object_name, $l10n );
     180    }
     181
    143182    function remove( $handles ) {
    144183        foreach ( (array) $handles as $handle )
     
    183222    var $deps = array();
    184223    var $ver = false;
    185     var $args = false;
     224    var $l10n_object = '';
     225    var $l10n = array();
    186226
    187227    function _WP_Script() {
     
    192232            $this->ver = false;
    193233    }
     234
     235    function localize( $object_name, $l10n ) {
     236        if ( !$object_name || !is_array($l10n) )
     237            return false;
     238        $this->l10n_object = $object_name;
     239        $this->l10n = $l10n;
     240        return true;
     241    }
    194242}
    195243
     
    228276}
    229277
     278/**
     279 * Localizes a script
     280 *
     281 * Localizes only if script has already been added
     282 *
     283 * @see WP_Script::localize()
     284 */
     285function wp_localize_script( $handle, $object_name, $l10n ) {
     286    global $wp_scripts;
     287    if ( !is_a($wp_scripts, 'WP_Scripts') )
     288        return false;
     289
     290    return $wp_scripts->localize( $handle, $object_name, $l10n );
     291}
     292
    230293function wp_deregister_script( $handle ) {
    231294    global $wp_scripts;
Note: See TracChangeset for help on using the changeset viewer.