Make WordPress Core

Changeset 7970


Ignore:
Timestamp:
05/21/2008 05:56:04 AM (18 years ago)
Author:
ryan
Message:

Style loader from mdawaffe. see #7011

Location:
trunk
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-header.php

    r7961 r7970  
    4646<style type="text/css">* html { overflow-x: hidden; }</style>
    4747<?php endif;
    48 if ( isset($page_hook) )
     48
     49if ( isset($page_hook) ) {
    4950        do_action('admin_print_scripts-' . $page_hook);
    50 else if ( isset($plugin_page) )
     51        do_action('admin_print_styles-' . $page_hook);
     52        do_action('admin_head-' . $page_hook);
     53} else if ( isset($plugin_page) ) {
    5154        do_action('admin_print_scripts-' . $plugin_page);
    52 else if ( isset($pagenow) )
     55        do_action('admin_print_styles-' . $plugin_page);
     56        do_action('admin_head-' . $plugin_page);
     57} else if ( isset($pagenow) ) {
    5358        do_action('admin_print_scripts-' . $pagenow);
     59        do_action('admin_print_styles-' . $pagenow);
     60        do_action('admin_head-' . $pagenow);
     61}
    5462do_action('admin_print_scripts');
     63do_action('admin_print_styles');
     64do_action('admin_head');
    5565
    56 if ( isset($page_hook) )
    57         do_action('admin_head-' . $page_hook);
    58 else if ( isset($plugin_page) )
    59         do_action('admin_head-' . $plugin_page);
    60 else if ( isset($pagenow) )
    61         do_action('admin_head-' . $pagenow);
    62 do_action('admin_head');
    6366?>
    6467</head>
  • trunk/wp-includes/default-filters.php

    r7747 r7970  
    176176add_action('sanitize_comment_cookies', 'sanitize_comment_cookies');
    177177add_action('admin_print_scripts', 'wp_print_scripts', 20);
     178add_action('admin_print_styles', 'wp_print_styles', 20);
    178179add_action('init', 'smilies_init', 5);
    179180add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
  • trunk/wp-includes/script-loader.php

    r7961 r7970  
    11<?php
    2 class WP_Scripts {
    3         var $scripts = array();
    4         var $queue = array();
    5         var $to_print = array();
    6         var $printed = array();
    7         var $args = array();
    8 
    9         function WP_Scripts() {
    10                 $this->default_scripts();
     2
     3require( ABSPATH . WPINC . '/class.wp-dependencies.php' );
     4require( ABSPATH . WPINC . '/class.wp-scripts.php' );
     5require( ABSPATH . WPINC . '/functions.wp-scripts.php' );
     6require( ABSPATH . WPINC . '/class.wp-styles.php' );
     7require( ABSPATH . WPINC . '/functions.wp-styles.php' );
     8
     9function wp_default_scripts( $scripts ) {
     10        $scripts->base_url = get_option( 'siteurl' );
     11        $scripts->default_version = get_bloginfo( 'version' );
     12
     13        $scripts->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' );
     14        $scripts->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' );
     15
     16        $scripts->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' );
     17        $scripts->localize( 'quicktags', 'quicktagsL10n', array(
     18                'quickLinks' => __('(Quick Links)'),
     19                'wordLookup' => __('Enter a word to look up:'),
     20                'dictionaryLookup' => attribute_escape(__('Dictionary lookup')),
     21                'lookup' => attribute_escape(__('lookup')),
     22                'closeAllOpenTags' => attribute_escape(__('Close all open tags')),
     23                'closeTags' => attribute_escape(__('close tags')),
     24                'enterURL' => __('Enter the URL'),
     25                'enterImageURL' => __('Enter the URL of the image'),
     26                'enterImageDescription' => __('Enter a description of the image')
     27        ) );
     28
     29        $scripts->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' );
     30
     31        // Let a plugin replace the visual editor
     32        $visual_editor = apply_filters('visual_editor', array('tiny_mce'));
     33        $scripts->add( 'editor', false, $visual_editor, '20080321' );
     34
     35        $scripts->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' );
     36
     37        // Modify this version when tinyMCE plugins are changed.
     38        $mce_version = apply_filters('tiny_mce_version', '20080423');
     39        $scripts->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
     40
     41        $scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
     42
     43        $scripts->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' );
     44        $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
     45                'noPerm' => __('You do not have permission to do that.'),
     46                'broken' => __('An unidentified error has occurred.')
     47        ) );
     48
     49        $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' );
     50
     51        $scripts->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306');
     52        $scripts->localize( 'wp-ajax', 'WPAjaxL10n', array(
     53                'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
     54                'permText' => __("You do not have permission to do that."),
     55                'strangeText' => __("Something strange happened.  Try refreshing the page."),
     56                'whoaText' => __("Slow down, I'm still sending your data!")
     57        ) );
     58
     59        $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' );
     60        $scripts->localize( 'wp-lists', 'wpListL10n', array(
     61                'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php'
     62        ) );
     63
     64        $scripts->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0');
     65        $scripts->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0');
     66        $scripts->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0');
     67        $scripts->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0');
     68        $scripts->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0');
     69        $scripts->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' );
     70        $scripts->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0');
     71        $scripts->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0');
     72
     73        $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
     74
     75        $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3');
     76        $scripts->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02');
     77        $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561');
     78        $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
     79        $scripts->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2');
     80        $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1');
     81        $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20');
     82        $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430');
     83        $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430');
     84        $scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2');
     85        $scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array(
     86                'is_lighttpd_before_150' => is_lighttpd_before_150(),
     87        ) );
     88        $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2');
     89        $scripts->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407');
     90        // these error messages came from the sample swfupload js, they might need changing.
     91        $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array(
     92                        'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
     93                        'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')),
     94                        'zero_byte_file' => __('This file is empty. Please try another.'),
     95                        'invalid_filetype' => __('This file type is not allowed. Please try another.'),
     96                        'default_error' => __('An error occurred in the upload. Please try again later.'),
     97                        'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
     98                        'upload_limit_exceeded' => __('You may only upload 1 file.'),
     99                        'http_error' => __('HTTP error.'),
     100                        'upload_failed' => __('Upload failed.'),
     101                        'io_error' => __('IO error.'),
     102                        'security_error' => __('Security error.'),
     103                        'file_cancelled' => __('File cancelled.'),
     104                        'upload_stopped' => __('Upload stopped.'),
     105                        'dismiss' => __('Dismiss'),
     106                        'crunching' => __('Crunching&hellip;'),
     107                        'deleted' => __('Deleted'),
     108        ) );
     109
     110        $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5b4' );
     111        $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5b4' );
     112
     113        if ( is_admin() ) {
     114                $scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
     115                $scripts->localize( 'ajaxcat', 'catL10n', array(
     116                        'add' => attribute_escape(__('Add')),
     117                        'how' => __('Separate multiple categories with commas.')
     118                ) );
     119                $scripts->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' );
     120                $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' );
     121                $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
     122                $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' );
     123                $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
     124                        'short' => __('Too short'),
     125                        'bad' => __('Bad'),
     126                        'good' => __('Good'),
     127                        'strong' => __('Strong')
     128                ) );
     129                $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080311' );
     130                $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
     131                        'pending' => __('%i% pending') // must look like: "# blah blah"
     132                ) );
     133                $scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
     134                $scripts->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080401');
     135                $scripts->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
     136                $scripts->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' );
     137                $scripts->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' );
     138                $scripts->localize( 'postbox', 'postboxL10n', array(
     139                        'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
     140                ) );
     141                $scripts->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' );
     142                $scripts->localize( 'slug', 'slugL10n', array(
     143                        'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
     144                        'save' => __('Save'),
     145                        'cancel' => __('Cancel'),
     146                ) );
     147                $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' );
     148                $scripts->localize( 'post', 'postL10n', array(
     149                        'tagsUsed' =>  __('Tags used on this post:'),
     150                        'add' => attribute_escape(__('Add')),
     151                        'addTag' => attribute_escape(__('Add new tag')),
     152                        'separate' => __('Separate tags with commas'),
     153                        'cancel' => __('Cancel'),
     154                        'edit' => __('Edit'),
     155                ) );
     156                $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080318' );
     157                $scripts->localize( 'page', 'postL10n', array(
     158                        'cancel' => __('Cancel'),
     159                        'edit' => __('Edit'),
     160                ) );
     161                $scripts->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' );
     162                $scripts->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' );
     163                $scripts->localize( 'comment', 'commentL10n', array(
     164                        'cancel' => __('Cancel'),
     165                        'edit' => __('Edit'),
     166                ) );
     167                $scripts->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080430' );
     168                $scripts->localize( 'upload', 'uploadL10n', array(
     169                        'browseTitle' => attribute_escape(__('Browse your files')),
     170                        'back' => __('&laquo; Back'),
     171                        'directTitle' => attribute_escape(__('Direct link to file')),
     172                        'edit' => __('Edit'),
     173                        'thumb' => __('Thumbnail'),
     174                        'full' => __('Full size'),
     175                        'icon' => __('Icon'),
     176                        'title' => __('Title'),
     177                        'show' => __('Show:'),
     178                        'link' => __('Link to:'),
     179                        'file' => __('File'),
     180                        'page' => __('Page'),
     181                        'none' => __('None'),
     182                        'editorText' => attribute_escape(__('Send to editor &raquo;')),
     183                        'insert' => __('Insert'),
     184                        'urlText' => __('URL'),
     185                        'desc' => __('Description'),
     186                        'deleteText' => attribute_escape(__('Delete File')),
     187                        'saveText' => attribute_escape(__('Save &raquo;')),
     188                        'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
     189                ) );
     190                $scripts->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' );
     191                $scripts->localize( 'admin-widgets', 'widgetsL10n', array(
     192                        'add' => __('Add'),
     193                        'edit' => __('Edit'),
     194                        'cancel' => __('Cancel'),
     195                ));
     196
     197                $scripts->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' );
     198                $scripts->localize( 'word-count', 'wordCountL10n', array(
     199                        'count' => __('Word count: %d')
     200                ));
     201               
     202                $scripts->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080511' );
     203                $scripts->localize( 'wp-gears', 'wpGearsL10n', array(
     204                        'updateCompleted' => __('Update completed.'),
     205                        'error' => __('Error:')
     206                ));
     207               
     208                $scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), '20080515' );
    11209        }
    12 
    13         function default_scripts() {
    14                 $this->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' );
    15                 $this->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' );
    16 
    17                 $this->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' );
    18                 $this->localize( 'quicktags', 'quicktagsL10n', array(
    19                         'quickLinks' => __('(Quick Links)'),
    20                         'wordLookup' => __('Enter a word to look up:'),
    21                         'dictionaryLookup' => attribute_escape(__('Dictionary lookup')),
    22                         'lookup' => attribute_escape(__('lookup')),
    23                         'closeAllOpenTags' => attribute_escape(__('Close all open tags')),
    24                         'closeTags' => attribute_escape(__('close tags')),
    25                         'enterURL' => __('Enter the URL'),
    26                         'enterImageURL' => __('Enter the URL of the image'),
    27                         'enterImageDescription' => __('Enter a description of the image')
    28                 ) );
    29 
    30                 $this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' );
    31 
    32                 // Let a plugin replace the visual editor
    33                 $visual_editor = apply_filters('visual_editor', array('tiny_mce'));
    34                 $this->add( 'editor', false, $visual_editor, '20080321' );
    35 
    36                 $this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' );
    37 
    38                 // Modify this version when tinyMCE plugins are changed.
    39                 $mce_version = apply_filters('tiny_mce_version', '20080423');
    40                 $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
    41 
    42                 $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
    43 
    44                 $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' );
    45                 $this->localize( 'wp-ajax-response', 'wpAjax', array(
    46                         'noPerm' => __('You do not have permission to do that.'),
    47                         'broken' => __('An unidentified error has occurred.')
    48                 ) );
    49 
    50                 $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' );
    51 
    52                 $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306');
    53                 $this->localize( 'wp-ajax', 'WPAjaxL10n', array(
    54                         'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
    55                         'permText' => __("You do not have permission to do that."),
    56                         'strangeText' => __("Something strange happened.  Try refreshing the page."),
    57                         'whoaText' => __("Slow down, I'm still sending your data!")
    58                 ) );
    59 
    60                 $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' );
    61                 $this->localize( 'wp-lists', 'wpListL10n', array(
    62                         'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php'
    63                 ) );
    64 
    65                 $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0');
    66                 $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0');
    67                 $this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0');
    68                 $this->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0');
    69                 $this->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0');
    70                 $this->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' );
    71                 $this->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0');
    72                 $this->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0');
    73 
    74                 $this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
    75 
    76                 $this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3');
    77                 $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02');
    78                 $this->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561');
    79                 $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
    80                 $this->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2');
    81                 $this->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1');
    82                 $this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20');
    83                 $this->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430');
    84                 $this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430');
    85                 $this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2');
    86                 $this->localize( 'swfupload-degrade', 'uploadDegradeOptions', array(
    87                         'is_lighttpd_before_150' => is_lighttpd_before_150(),
    88                 ) );
    89                 $this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2');
    90                 $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407');
    91                 // these error messages came from the sample swfupload js, they might need changing.
    92                 $this->localize( 'swfupload-handlers', 'swfuploadL10n', array(
    93                                 'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
    94                                 'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')),
    95                                 'zero_byte_file' => __('This file is empty. Please try another.'),
    96                                 'invalid_filetype' => __('This file type is not allowed. Please try another.'),
    97                                 'default_error' => __('An error occurred in the upload. Please try again later.'),
    98                                 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
    99                                 'upload_limit_exceeded' => __('You may only upload 1 file.'),
    100                                 'http_error' => __('HTTP error.'),
    101                                 'upload_failed' => __('Upload failed.'),
    102                                 'io_error' => __('IO error.'),
    103                                 'security_error' => __('Security error.'),
    104                                 'file_cancelled' => __('File cancelled.'),
    105                                 'upload_stopped' => __('Upload stopped.'),
    106                                 'dismiss' => __('Dismiss'),
    107                                 'crunching' => __('Crunching&hellip;'),
    108                                 'deleted' => __('Deleted'),
    109                 ) );
    110 
    111                 $this->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5b4' );
    112                 $this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5b4' );
    113 
    114                 if ( is_admin() ) {
    115                         $this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
    116                         $this->localize( 'ajaxcat', 'catL10n', array(
    117                                 'add' => attribute_escape(__('Add')),
    118                                 'how' => __('Separate multiple categories with commas.')
    119                         ) );
    120                         $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' );
    121                         $this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' );
    122                         $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
    123                         $this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' );
    124                         $this->localize( 'password-strength-meter', 'pwsL10n', array(
    125                                 'short' => __('Too short'),
    126                                 'bad' => __('Bad'),
    127                                 'good' => __('Good'),
    128                                 'strong' => __('Strong')
    129                         ) );
    130                         $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080311' );
    131                         $this->localize( 'admin-comments', 'adminCommentsL10n', array(
    132                                 'pending' => __('%i% pending') // must look like: "# blah blah"
    133                         ) );
    134                         $this->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
    135                         $this->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080401');
    136                         $this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
    137                         $this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' );
    138                         $this->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' );
    139                         $this->localize( 'postbox', 'postboxL10n', array(
    140                                 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
    141                         ) );
    142                         $this->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' );
    143                         $this->localize( 'slug', 'slugL10n', array(
    144                                 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
    145                                 'save' => __('Save'),
    146                                 'cancel' => __('Cancel'),
    147                         ) );
    148                         $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' );
    149                         $this->localize( 'post', 'postL10n', array(
    150                                 'tagsUsed' =>  __('Tags used on this post:'),
    151                                 'add' => attribute_escape(__('Add')),
    152                                 'addTag' => attribute_escape(__('Add new tag')),
    153                                 'separate' => __('Separate tags with commas'),
    154                                 'cancel' => __('Cancel'),
    155                                 'edit' => __('Edit'),
    156                         ) );
    157                         $this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080318' );
    158                         $this->localize( 'page', 'postL10n', array(
    159                                 'cancel' => __('Cancel'),
    160                                 'edit' => __('Edit'),
    161                         ) );
    162                         $this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' );
    163                         $this->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' );
    164                         $this->localize( 'comment', 'commentL10n', array(
    165                                         'cancel' => __('Cancel'),
    166                                         'edit' => __('Edit'),
    167                                 ) );
    168                         $this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080430' );
    169                         $this->localize( 'upload', 'uploadL10n', array(
    170                                 'browseTitle' => attribute_escape(__('Browse your files')),
    171                                 'back' => __('&laquo; Back'),
    172                                 'directTitle' => attribute_escape(__('Direct link to file')),
    173                                 'edit' => __('Edit'),
    174                                 'thumb' => __('Thumbnail'),
    175                                 'full' => __('Full size'),
    176                                 'icon' => __('Icon'),
    177                                 'title' => __('Title'),
    178                                 'show' => __('Show:'),
    179                                 'link' => __('Link to:'),
    180                                 'file' => __('File'),
    181                                 'page' => __('Page'),
    182                                 'none' => __('None'),
    183                                 'editorText' => attribute_escape(__('Send to editor &raquo;')),
    184                                 'insert' => __('Insert'),
    185                                 'urlText' => __('URL'),
    186                                 'desc' => __('Description'),
    187                                 'deleteText' => attribute_escape(__('Delete File')),
    188                                 'saveText' => attribute_escape(__('Save &raquo;')),
    189                                 'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
    190                         ) );
    191                         $this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' );
    192                         $this->localize( 'admin-widgets', 'widgetsL10n', array(
    193                                 'add' => __('Add'),
    194                                 'edit' => __('Edit'),
    195                                 'cancel' => __('Cancel'),
    196                         ));
    197 
    198                         $this->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' );
    199                         $this->localize( 'word-count', 'wordCountL10n', array(
    200                                 'count' => __('Word count: %d')
    201                         ));
    202                        
    203                         $this->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080511' );
    204                         $this->localize( 'wp-gears', 'wpGearsL10n', array(
    205                                 'updateCompleted' => __('Update completed.'),
    206                                 'error' => __('Error:')
    207                         ));
    208                        
    209                         $this->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), '20080515' );
    210                 }
    211         }
    212 
    213         /**
    214          * Prints script tags
    215          *
    216          * Prints the scripts passed to it or the print queue.  Also prints all necessary dependencies.
    217          *
    218          * @param mixed handles (optional) Scripts to be printed.  (void) prints queue, (string) prints that script, (array of strings) prints those scripts.
    219          * @return array Scripts that have been printed
    220          */
    221         function print_scripts( $handles = false ) {
    222                 global $wp_db_version;
    223 
    224                 // Print the queue if nothing is passed.  If a string is passed, print that script.  If an array is passed, print those scripts.
    225                 $handles = false === $handles ? $this->queue : (array) $handles;
    226                 $this->all_deps( $handles );
    227 
    228                 $to_print = apply_filters( 'print_scripts_array', array_keys($this->to_print) );
    229 
    230                 foreach( $to_print as $handle ) {
    231                         if ( !in_array($handle, $this->printed) && isset($this->scripts[$handle]) ) {
    232                                 if ( $this->scripts[$handle]->src ) { // Else it defines a group.
    233                                         $ver = $this->scripts[$handle]->ver ? $this->scripts[$handle]->ver : $wp_db_version;
    234                                         if ( isset($this->args[$handle]) )
    235                                                 $ver .= '&amp;' . $this->args[$handle];
    236                                         $src = 0 === strpos($this->scripts[$handle]->src, 'http://') ? $this->scripts[$handle]->src : get_option( 'siteurl' ) . $this->scripts[$handle]->src;
    237                                         $src = $this->scripts[$handle]->src;
    238 
    239                                         if (!preg_match('|^https?://|', $src)) {
    240                                                 $src = get_option('siteurl') . $src;
    241                                         }
    242 
    243                                         $src = add_query_arg('ver', $ver, $src);
    244                                         $src = clean_url(apply_filters( 'script_loader_src', $src ));
    245                                         $this->print_scripts_l10n( $handle );
    246                                         echo "<script type='text/javascript' src='$src'></script>\n";
    247                                 }
    248                                 $this->printed[] = $handle;
    249                         }
    250                 }
    251 
    252                 $this->to_print = array();
    253                 return $this->printed;
    254         }
    255 
    256         function print_scripts_l10n( $handle ) {
    257                 if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) )
    258                         return;
    259 
    260                 $object_name = $this->scripts[$handle]->l10n_object;
    261 
    262                 echo "<script type='text/javascript'>\n";
    263                 echo "/* <![CDATA[ */\n";
    264                 echo "\t$object_name = {\n";
    265                 $eol = '';
    266                 foreach ( $this->scripts[$handle]->l10n as $var => $val ) {
    267                         echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
    268                         $eol = ",\n";
    269                 }
    270                 echo "\n\t}\n";
    271                 echo "/* ]]> */\n";
    272                 echo "</script>\n";
    273         }
    274 
    275         /**
    276          * Determines dependencies of scripts
    277          *
    278          * Recursively builds array of scripts to print taking dependencies into account.  Does NOT catch infinite loops.
    279          *
    280          * @param mixed handles Accepts (string) script name or (array of strings) script names
    281          * @param bool recursion Used internally when function calls itself
    282          */
    283         function all_deps( $handles, $recursion = false ) {
    284                 if ( !$handles = (array) $handles )
    285                         return false;
    286 
    287                 foreach ( $handles as $handle ) {
    288                         $handle = explode('?', $handle);
    289                         if ( isset($handle[1]) )
    290                                 $this->args[$handle[0]] = $handle[1];
    291                         $handle = $handle[0];
    292 
    293                         if ( isset($this->to_print[$handle]) ) // Already grobbed it and its deps
    294                                 continue;
    295 
    296                         $keep_going = true;
    297                         if ( !isset($this->scripts[$handle]) )
    298                                 $keep_going = false; // Script doesn't exist
    299                         elseif ( $this->scripts[$handle]->deps && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) )
    300                                 $keep_going = false; // Script requires deps which don't exist (not a necessary check.  efficiency?)
    301                         elseif ( $this->scripts[$handle]->deps && !$this->all_deps( $this->scripts[$handle]->deps, true ) )
    302                                 $keep_going = false; // Script requires deps which don't exist
    303 
    304                         if ( !$keep_going ) { // Either script or its deps don't exist.
    305                                 if ( $recursion )
    306                                         return false; // Abort this branch.
    307                                 else
    308                                         continue; // We're at the top level.  Move on to the next one.
    309                         }
    310 
    311                         $this->to_print[$handle] = true;
    312                 }
    313 
    314                 return true;
    315         }
    316 
    317         /**
    318          * Adds script
    319          *
    320          * Adds the script only if no script of that name already exists
    321          *
    322          * @param string handle Script name
    323          * @param string src Script url
    324          * @param array deps (optional) Array of script names on which this script depends
    325          * @param string ver (optional) Script version (used for cache busting)
    326          * @return array Hierarchical array of dependencies
    327          */
    328         function add( $handle, $src, $deps = array(), $ver = false ) {
    329                 if ( isset($this->scripts[$handle]) )
    330                         return false;
    331                 $this->scripts[$handle] = new _WP_Script( $handle, $src, $deps, $ver );
    332                 return true;
    333         }
    334 
    335         /**
    336          * Localizes a script
    337          *
    338          * Localizes only if script has already been added
    339          *
    340          * @param string handle Script name
    341          * @param string object_name Name of JS object to hold l10n info
    342          * @param array l10n Array of JS var name => localized string
    343          * @return bool Successful localization
    344          */
    345         function localize( $handle, $object_name, $l10n ) {
    346                 if ( !isset($this->scripts[$handle]) )
    347                         return false;
    348                 return $this->scripts[$handle]->localize( $object_name, $l10n );
    349         }
    350 
    351         function remove( $handles ) {
    352                 foreach ( (array) $handles as $handle )
    353                         unset($this->scripts[$handle]);
    354         }
    355 
    356         function enqueue( $handles ) {
    357                 foreach ( (array) $handles as $handle ) {
    358                         $handle = explode('?', $handle);
    359                         if ( !in_array($handle[0], $this->queue) && isset($this->scripts[$handle[0]]) ) {
    360                                 $this->queue[] = $handle[0];
    361                                 if ( isset($handle[1]) )
    362                                         $this->args[$handle[0]] = $handle[1];
    363                         }
    364                 }
    365         }
    366 
    367         function dequeue( $handles ) {
    368                 foreach ( (array) $handles as $handle )
    369                         unset( $this->queue[$handle] );
    370         }
    371 
    372         function query( $handle, $list = 'scripts' ) { // scripts, queue, or printed
    373                 switch ( $list ) :
    374                 case 'scripts':
    375                         if ( isset($this->scripts[$handle]) )
    376                                 return $this->scripts[$handle];
    377                         break;
    378                 default:
    379                         if ( in_array($handle, $this->$list) )
    380                                 return true;
    381                         break;
    382                 endswitch;
    383                 return false;
    384         }
    385 
    386 }
    387 
    388 class _WP_Script {
    389         var $handle;
    390         var $src;
    391         var $deps = array();
    392         var $ver = false;
    393         var $l10n_object = '';
    394         var $l10n = array();
    395 
    396         function _WP_Script() {
    397                 @list($this->handle, $this->src, $this->deps, $this->ver) = func_get_args();
    398                 if ( !is_array($this->deps) )
    399                         $this->deps = array();
    400                 if ( !$this->ver )
    401                         $this->ver = false;
    402         }
    403 
    404         function localize( $object_name, $l10n ) {
    405                 if ( !$object_name || !is_array($l10n) )
    406                         return false;
    407                 $this->l10n_object = $object_name;
    408                 $this->l10n = $l10n;
    409                 return true;
    410         }
    411 }
    412 
    413 /**
    414  * Prints script tags in document head
    415  *
    416  * Called by admin-header.php and by wp_head hook. Since it is called by wp_head on every page load,
    417  * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
    418  * Does make use of already instantiated $wp_scripts if present.
    419  * Use provided wp_print_scripts hook to register/enqueue new scripts.
    420  *
    421  * @see WP_Scripts::print_scripts()
    422  */
    423 function wp_print_scripts( $handles = false ) {
    424         do_action( 'wp_print_scripts' );
    425         if ( '' === $handles ) // for wp_head
    426                 $handles = false;
    427 
    428         global $wp_scripts;
    429         if ( !is_a($wp_scripts, 'WP_Scripts') ) {
    430                 if ( !$handles )
    431                         return array(); // No need to instantiate if nothing's there.
    432                 else
    433                         $wp_scripts = new WP_Scripts();
    434         }
    435 
    436         return $wp_scripts->print_scripts( $handles );
    437 }
    438 
    439 function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
    440         global $wp_scripts;
    441         if ( !is_a($wp_scripts, 'WP_Scripts') )
    442                 $wp_scripts = new WP_Scripts();
    443 
    444         $wp_scripts->add( $handle, $src, $deps, $ver );
    445 }
    446 
    447 /**
    448  * Localizes a script
    449  *
    450  * Localizes only if script has already been added
    451  *
    452  * @see WP_Script::localize()
    453  */
    454 function wp_localize_script( $handle, $object_name, $l10n ) {
    455         global $wp_scripts;
    456         if ( !is_a($wp_scripts, 'WP_Scripts') )
    457                 return false;
    458 
    459         return $wp_scripts->localize( $handle, $object_name, $l10n );
    460 }
    461 
    462 function wp_deregister_script( $handle ) {
    463         global $wp_scripts;
    464         if ( !is_a($wp_scripts, 'WP_Scripts') )
    465                 $wp_scripts = new WP_Scripts();
    466 
    467         $wp_scripts->remove( $handle );
    468 }
    469 
    470 /**
    471  * Equeues script
    472  *
    473  * Registers the script if src provided (does NOT overwrite) and enqueues.
    474  *
    475  * @see WP_Script::add(), WP_Script::enqueue()
    476 */
    477 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) {
    478         global $wp_scripts;
    479         if ( !is_a($wp_scripts, 'WP_Scripts') )
    480                 $wp_scripts = new WP_Scripts();
    481 
    482         if ( $src ) {
    483                 $_handle = explode('?', $handle);
    484                 $wp_scripts->add( $_handle[0], $src, $deps, $ver );
    485         }
    486         $wp_scripts->enqueue( $handle );
    487210}
    488211
     
    516239}
    517240
     241add_action( 'wp_default_scripts', 'wp_default_scripts' );
    518242add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
    519243add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
    520 
    521 ?>
Note: See TracChangeset for help on using the changeset viewer.