2006-05-22 19:16:05 +02:00
|
|
|
<?php
|
|
|
|
class WP_Scripts {
|
|
|
|
var $scripts = array();
|
|
|
|
var $queue = array();
|
2007-09-19 02:51:21 +02:00
|
|
|
var $to_print = array();
|
2006-05-22 19:16:05 +02:00
|
|
|
var $printed = array();
|
|
|
|
var $args = array();
|
|
|
|
|
|
|
|
function WP_Scripts() {
|
|
|
|
$this->default_scripts();
|
|
|
|
}
|
|
|
|
|
|
|
|
function default_scripts() {
|
2008-01-09 13:12:35 +01:00
|
|
|
$this->add( 'common', '/wp-admin/js/common.js', false, '1.0' );
|
2007-01-19 02:10:32 +01:00
|
|
|
$this->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-04-01 18:06:19 +02:00
|
|
|
$this->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' );
|
|
|
|
$this->localize( 'quicktags', 'quicktagsL10n', array(
|
|
|
|
'quickLinks' => __('(Quick Links)'),
|
|
|
|
'wordLookup' => __('Enter a word to look up:'),
|
|
|
|
'dictionaryLookup' => attribute_escape(__('Dictionary lookup')),
|
|
|
|
'lookup' => attribute_escape(__('lookup')),
|
|
|
|
'closeAllOpenTags' => attribute_escape(__('Close all open tags')),
|
|
|
|
'closeTags' => attribute_escape(__('close tags')),
|
|
|
|
'enterURL' => __('Enter the URL'),
|
|
|
|
'enterImageURL' => __('Enter the URL of the image'),
|
|
|
|
'enterImageDescription' => __('Enter a description of the image')
|
|
|
|
) );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
$this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', false, '3517' );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2008-02-18 18:11:12 +01:00
|
|
|
// Let a plugin replace the visual editor
|
|
|
|
$visual_editor = apply_filters('visual_editor', array('tiny_mce'));
|
|
|
|
$this->add( 'editor', false, $visual_editor, '20080218' );
|
|
|
|
|
2008-02-21 22:40:25 +01:00
|
|
|
$this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080221' );
|
2008-02-18 18:11:12 +01:00
|
|
|
|
|
|
|
// Modify this version when tinyMCE plugins are changed.
|
2008-02-27 06:36:42 +01:00
|
|
|
$mce_version = apply_filters('tiny_mce_version', '20080226');
|
2008-02-18 18:11:12 +01:00
|
|
|
$this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
|
2008-02-09 14:08:28 +01:00
|
|
|
|
2007-12-28 20:17:21 +01:00
|
|
|
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2008-02-29 10:51:36 +01:00
|
|
|
$this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080229' . mt_rand() );
|
|
|
|
$this->localize( 'wp-ajax-response', 'wpAjax', array(
|
|
|
|
'noPerm' => 'You do not have permission to do that.',
|
|
|
|
'broken' => 'AJAX is teh b0rked.'
|
|
|
|
) );
|
|
|
|
|
|
|
|
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080221' . mt_rand());
|
2007-03-06 18:35:01 +01:00
|
|
|
$this->localize( 'autosave', 'autosaveL10n', array(
|
2008-02-29 10:51:36 +01:00
|
|
|
'autosaveInterval' => get_option( 'autosave_interval' ),
|
|
|
|
'previewPageText' => __('View this Page'),
|
|
|
|
'previewPostText' => __('View this Post'),
|
2007-03-06 18:35:01 +01:00
|
|
|
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
2008-02-29 10:51:36 +01:00
|
|
|
'savingText' => __('Saving…')
|
2007-03-06 18:35:01 +01:00
|
|
|
) );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-03-06 18:35:01 +01:00
|
|
|
$this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306');
|
|
|
|
$this->localize( 'wp-ajax', 'WPAjaxL10n', array(
|
|
|
|
'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
|
|
|
'permText' => __("You don't have permission to do that."),
|
|
|
|
'strangeText' => __("Something strange happened. Try refreshing the page."),
|
|
|
|
'whoaText' => __("Slow down, I'm still sending your data!")
|
|
|
|
) );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2008-02-29 10:51:36 +01:00
|
|
|
$this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080228' . mt_rand());
|
2007-10-10 00:49:42 +02:00
|
|
|
$this->localize( 'wp-lists', 'wpListL10n', array(
|
|
|
|
'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php'
|
|
|
|
) );
|
|
|
|
|
2007-12-28 20:17:21 +01:00
|
|
|
$this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0');
|
|
|
|
$this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0');
|
|
|
|
$this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0');
|
|
|
|
$this->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0');
|
|
|
|
$this->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0');
|
|
|
|
$this->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' );
|
|
|
|
$this->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0');
|
|
|
|
$this->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0');
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-01-19 01:49:01 +01:00
|
|
|
$this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2008-02-08 08:33:51 +01:00
|
|
|
$this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3');
|
2008-01-07 18:23:40 +01:00
|
|
|
$this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02');
|
2008-02-26 23:51:16 +01:00
|
|
|
$this->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561');
|
2008-01-05 00:34:33 +01:00
|
|
|
$this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
|
2008-01-03 02:34:11 +01:00
|
|
|
$this->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2');
|
|
|
|
$this->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1');
|
2008-01-04 09:46:33 +01:00
|
|
|
$this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20');
|
2008-01-09 09:14:29 +01:00
|
|
|
$this->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1');
|
2008-01-25 20:21:11 +01:00
|
|
|
$this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2');
|
|
|
|
$this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2');
|
|
|
|
$this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2');
|
2008-02-29 07:54:15 +01:00
|
|
|
$this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080228');
|
2008-01-25 20:21:11 +01:00
|
|
|
// these error messages came from the sample swfupload js, they might need changing.
|
|
|
|
$this->localize( 'swfupload-handlers', 'swfuploadL10n', array(
|
2008-02-29 07:54:15 +01:00
|
|
|
'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
|
|
|
|
'file_exceeds_size_limit' => __('This file is too big. See php.ini.'),
|
|
|
|
'zero_byte_file' => __('The file you selected is empty. Please select another file.'),
|
|
|
|
'invalid_filetype' => __('The file you choose is not an allowed file type.'),
|
|
|
|
'default_error' => __('An error occurred in the upload. Please try again later.'),
|
|
|
|
'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
|
|
|
|
'upload_limit_exceeded' => __('You may only upload 1 file.'),
|
|
|
|
'http_error' => __('HTTP error.'),
|
|
|
|
'upload_failed' => __('Upload failed.'),
|
|
|
|
'io_error' => __('IO error.'),
|
|
|
|
'security_error' => __('Security error.'),
|
|
|
|
'file_cancelled' => __('File cancelled.'),
|
|
|
|
'upload_stopped' => __('Upload stopped.'),
|
|
|
|
'dismiss' => __('Dismiss'),
|
2008-01-25 20:21:11 +01:00
|
|
|
) );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2008-01-10 10:39:35 +01:00
|
|
|
$this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery'), '3' );
|
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
if ( is_admin() ) {
|
2007-11-01 07:23:16 +01:00
|
|
|
$this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
|
2007-03-06 18:35:01 +01:00
|
|
|
$this->localize( 'ajaxcat', 'catL10n', array(
|
|
|
|
'add' => attribute_escape(__('Add')),
|
|
|
|
'how' => __('Separate multiple categories with commas.')
|
|
|
|
) );
|
2007-10-31 04:53:32 +01:00
|
|
|
$this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' );
|
2008-01-25 20:29:01 +01:00
|
|
|
$this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' );
|
2007-10-10 00:49:42 +02:00
|
|
|
$this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
|
2008-02-05 07:47:27 +01:00
|
|
|
$this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' );
|
|
|
|
$this->localize( 'password-strength-meter', 'pwsL10n', array(
|
|
|
|
'short' => __('Too short'),
|
|
|
|
'bad' => __('Bad'),
|
|
|
|
'good' => __('Good'),
|
|
|
|
'strong' => __('Strong')
|
2007-12-19 22:53:10 +01:00
|
|
|
) );
|
2008-02-28 07:50:25 +01:00
|
|
|
$this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080228' );
|
2007-10-10 00:49:42 +02:00
|
|
|
$this->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
|
2008-02-27 01:46:27 +01:00
|
|
|
$this->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080108' );
|
2007-06-02 02:37:51 +02:00
|
|
|
$this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
|
|
|
|
$this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' );
|
2008-01-28 22:34:42 +01:00
|
|
|
$this->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' );
|
2008-02-02 21:31:56 +01:00
|
|
|
$this->localize( 'postbox', 'postboxL10n', array(
|
|
|
|
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
|
|
|
) );
|
2008-02-08 20:57:50 +01:00
|
|
|
$this->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' );
|
|
|
|
$this->localize( 'slug', 'slugL10n', array(
|
|
|
|
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
|
|
|
'save' => __('Save'),
|
|
|
|
'cancel' => __('Cancel'),
|
|
|
|
) );
|
2008-02-21 21:19:34 +01:00
|
|
|
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080221' );
|
2008-01-09 18:46:13 +01:00
|
|
|
$this->localize( 'post', 'postL10n', array(
|
|
|
|
'tagsUsed' => __('Tags used on this post:'),
|
|
|
|
'add' => attribute_escape(__('Add')),
|
|
|
|
'addTag' => attribute_escape(__('Add new tag')),
|
|
|
|
'separate' => __('Separate tags with commas'),
|
|
|
|
) );
|
2008-02-08 20:57:50 +01:00
|
|
|
$this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080208' );
|
2008-01-31 21:04:54 +01:00
|
|
|
$this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' );
|
2008-02-20 03:41:16 +01:00
|
|
|
$this->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' );
|
2008-01-09 09:14:29 +01:00
|
|
|
$this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080109' );
|
2007-03-06 18:35:01 +01:00
|
|
|
$this->localize( 'upload', 'uploadL10n', array(
|
|
|
|
'browseTitle' => attribute_escape(__('Browse your files')),
|
|
|
|
'back' => __('« Back'),
|
|
|
|
'directTitle' => attribute_escape(__('Direct link to file')),
|
|
|
|
'edit' => __('Edit'),
|
|
|
|
'thumb' => __('Thumbnail'),
|
|
|
|
'full' => __('Full size'),
|
|
|
|
'icon' => __('Icon'),
|
|
|
|
'title' => __('Title'),
|
|
|
|
'show' => __('Show:'),
|
|
|
|
'link' => __('Link to:'),
|
|
|
|
'file' => __('File'),
|
|
|
|
'page' => __('Page'),
|
|
|
|
'none' => __('None'),
|
|
|
|
'editorText' => attribute_escape(__('Send to editor »')),
|
|
|
|
'insert' => __('Insert'),
|
|
|
|
'urlText' => __('URL'),
|
|
|
|
'desc' => __('Description'),
|
|
|
|
'deleteText' => attribute_escape(__('Delete File')),
|
|
|
|
'saveText' => attribute_escape(__('Save »')),
|
|
|
|
'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
|
|
|
|
) );
|
2008-01-10 10:39:35 +01:00
|
|
|
$this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080109' );
|
2008-01-30 22:49:56 +01:00
|
|
|
$this->localize( 'admin-widgets', 'widgetsL10n', array(
|
|
|
|
'add' => __('Add'),
|
|
|
|
'edit' => __('Edit'),
|
|
|
|
'cancel' => __('Cancel'),
|
|
|
|
));
|
2008-02-21 22:40:25 +01:00
|
|
|
$this->add( 'editor', '/wp-admin/js/editor.js', array('tiny_mce'), '20080221' );
|
2006-05-22 19:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints script tags
|
|
|
|
*
|
|
|
|
* Prints the scripts passed to it or the print queue. Also prints all necessary dependencies.
|
|
|
|
*
|
|
|
|
* @param mixed handles (optional) Scripts to be printed. (void) prints queue, (string) prints that script, (array of strings) prints those scripts.
|
|
|
|
* @return array Scripts that have been printed
|
|
|
|
*/
|
|
|
|
function print_scripts( $handles = false ) {
|
2007-09-19 02:51:21 +02:00
|
|
|
global $wp_db_version;
|
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
// Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts.
|
|
|
|
$handles = false === $handles ? $this->queue : (array) $handles;
|
2007-09-19 02:51:21 +02:00
|
|
|
$this->all_deps( $handles );
|
2006-05-22 19:16:05 +02:00
|
|
|
|
2007-09-19 02:51:21 +02:00
|
|
|
$to_print = apply_filters( 'print_scripts_array', array_keys($this->to_print) );
|
2006-05-22 19:16:05 +02:00
|
|
|
|
2007-09-19 02:51:21 +02:00
|
|
|
foreach( $to_print as $handle ) {
|
2006-05-22 19:16:05 +02:00
|
|
|
if ( !in_array($handle, $this->printed) && isset($this->scripts[$handle]) ) {
|
2007-01-08 04:03:36 +01:00
|
|
|
if ( $this->scripts[$handle]->src ) { // Else it defines a group.
|
|
|
|
$ver = $this->scripts[$handle]->ver ? $this->scripts[$handle]->ver : $wp_db_version;
|
|
|
|
if ( isset($this->args[$handle]) )
|
|
|
|
$ver .= '&' . $this->args[$handle];
|
|
|
|
$src = 0 === strpos($this->scripts[$handle]->src, 'http://') ? $this->scripts[$handle]->src : get_option( 'siteurl' ) . $this->scripts[$handle]->src;
|
2007-03-31 04:47:23 +02:00
|
|
|
$src = $this->scripts[$handle]->src;
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-03-31 04:47:23 +02:00
|
|
|
if (!preg_match('|^https?://|', $src)) {
|
|
|
|
$src = get_option('siteurl') . $src;
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-01-08 04:03:36 +01:00
|
|
|
$src = add_query_arg('ver', $ver, $src);
|
2007-03-17 09:46:59 +01:00
|
|
|
$src = clean_url(apply_filters( 'script_loader_src', $src ));
|
2007-03-06 01:39:46 +01:00
|
|
|
$this->print_scripts_l10n( $handle );
|
2007-10-10 20:51:12 +02:00
|
|
|
echo "<script type='text/javascript' src='$src'></script>\n";
|
2007-01-08 04:03:36 +01:00
|
|
|
}
|
2006-05-22 19:16:05 +02:00
|
|
|
$this->printed[] = $handle;
|
|
|
|
}
|
|
|
|
}
|
2007-09-19 02:51:21 +02:00
|
|
|
|
|
|
|
$this->to_print = array();
|
|
|
|
return $this->printed;
|
2006-05-22 19:16:05 +02:00
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-03-06 01:39:46 +01:00
|
|
|
function print_scripts_l10n( $handle ) {
|
|
|
|
if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$object_name = $this->scripts[$handle]->l10n_object;
|
|
|
|
|
|
|
|
echo "<script type='text/javascript'>\n";
|
|
|
|
echo "/* <![CDATA[ */\n";
|
2007-07-17 21:26:03 +02:00
|
|
|
echo "\t$object_name = {\n";
|
|
|
|
$eol = '';
|
|
|
|
foreach ( $this->scripts[$handle]->l10n as $var => $val ) {
|
|
|
|
echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
|
|
|
|
$eol = ",\n";
|
2007-07-16 21:22:27 +02:00
|
|
|
}
|
2007-07-17 21:26:03 +02:00
|
|
|
echo "\n\t}\n";
|
|
|
|
echo "/* ]]> */\n";
|
|
|
|
echo "</script>\n";
|
2007-07-16 21:22:27 +02:00
|
|
|
}
|
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
/**
|
|
|
|
* Determines dependencies of scripts
|
|
|
|
*
|
2007-09-19 02:51:21 +02:00
|
|
|
* Recursively builds array of scripts to print taking dependencies into account. Does NOT catch infinite loops.
|
2006-05-22 19:16:05 +02:00
|
|
|
*
|
|
|
|
* @param mixed handles Accepts (string) script name or (array of strings) script names
|
|
|
|
* @param bool recursion Used internally when function calls itself
|
|
|
|
*/
|
|
|
|
function all_deps( $handles, $recursion = false ) {
|
2007-09-19 02:51:21 +02:00
|
|
|
if ( !$handles = (array) $handles )
|
|
|
|
return false;
|
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
foreach ( $handles as $handle ) {
|
|
|
|
$handle = explode('?', $handle);
|
|
|
|
if ( isset($handle[1]) )
|
|
|
|
$this->args[$handle[0]] = $handle[1];
|
|
|
|
$handle = $handle[0];
|
2007-09-19 02:51:21 +02:00
|
|
|
|
|
|
|
if ( isset($this->to_print[$handle]) ) // Already grobbed it and its deps
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$keep_going = true;
|
|
|
|
if ( !isset($this->scripts[$handle]) )
|
|
|
|
$keep_going = false; // Script doesn't exist
|
|
|
|
elseif ( $this->scripts[$handle]->deps && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) )
|
|
|
|
$keep_going = false; // Script requires deps which don't exist (not a necessary check. efficiency?)
|
|
|
|
elseif ( $this->scripts[$handle]->deps && !$this->all_deps( $this->scripts[$handle]->deps, true ) )
|
|
|
|
$keep_going = false; // Script requires deps which don't exist
|
|
|
|
|
|
|
|
if ( !$keep_going ) { // Either script or its deps don't exist.
|
|
|
|
if ( $recursion )
|
|
|
|
return false; // Abort this branch.
|
2006-05-22 19:16:05 +02:00
|
|
|
else
|
2007-09-19 02:51:21 +02:00
|
|
|
continue; // We're at the top level. Move on to the next one.
|
2008-02-05 07:47:27 +01:00
|
|
|
}
|
2007-09-19 02:51:21 +02:00
|
|
|
|
|
|
|
$this->to_print[$handle] = true;
|
2006-05-22 19:16:05 +02:00
|
|
|
}
|
2007-09-19 02:51:21 +02:00
|
|
|
|
|
|
|
return true;
|
2006-05-22 19:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds script
|
|
|
|
*
|
|
|
|
* Adds the script only if no script of that name already exists
|
|
|
|
*
|
|
|
|
* @param string handle Script name
|
|
|
|
* @param string src Script url
|
|
|
|
* @param array deps (optional) Array of script names on which this script depends
|
|
|
|
* @param string ver (optional) Script version (used for cache busting)
|
|
|
|
* @return array Hierarchical array of dependencies
|
|
|
|
*/
|
|
|
|
function add( $handle, $src, $deps = array(), $ver = false ) {
|
|
|
|
if ( isset($this->scripts[$handle]) )
|
|
|
|
return false;
|
|
|
|
$this->scripts[$handle] = new _WP_Script( $handle, $src, $deps, $ver );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-06 01:39:46 +01:00
|
|
|
/**
|
|
|
|
* Localizes a script
|
|
|
|
*
|
|
|
|
* Localizes only if script has already been added
|
|
|
|
*
|
|
|
|
* @param string handle Script name
|
|
|
|
* @param string object_name Name of JS object to hold l10n info
|
|
|
|
* @param array l10n Array of JS var name => localized string
|
|
|
|
* @return bool Successful localization
|
|
|
|
*/
|
|
|
|
function localize( $handle, $object_name, $l10n ) {
|
|
|
|
if ( !isset($this->scripts[$handle]) )
|
|
|
|
return false;
|
|
|
|
return $this->scripts[$handle]->localize( $object_name, $l10n );
|
|
|
|
}
|
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
function remove( $handles ) {
|
|
|
|
foreach ( (array) $handles as $handle )
|
|
|
|
unset($this->scripts[$handle]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function enqueue( $handles ) {
|
|
|
|
foreach ( (array) $handles as $handle ) {
|
|
|
|
$handle = explode('?', $handle);
|
|
|
|
if ( !in_array($handle[0], $this->queue) && isset($this->scripts[$handle[0]]) ) {
|
|
|
|
$this->queue[] = $handle[0];
|
|
|
|
if ( isset($handle[1]) )
|
|
|
|
$this->args[$handle[0]] = $handle[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dequeue( $handles ) {
|
|
|
|
foreach ( (array) $handles as $handle )
|
|
|
|
unset( $this->queue[$handle] );
|
|
|
|
}
|
|
|
|
|
|
|
|
function query( $handle, $list = 'scripts' ) { // scripts, queue, or printed
|
|
|
|
switch ( $list ) :
|
|
|
|
case 'scripts':
|
|
|
|
if ( isset($this->scripts[$handle]) )
|
|
|
|
return $this->scripts[$handle];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ( in_array($handle, $this->$list) )
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
endswitch;
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class _WP_Script {
|
|
|
|
var $handle;
|
|
|
|
var $src;
|
|
|
|
var $deps = array();
|
|
|
|
var $ver = false;
|
2007-03-06 01:39:46 +01:00
|
|
|
var $l10n_object = '';
|
|
|
|
var $l10n = array();
|
2006-05-22 19:16:05 +02:00
|
|
|
|
|
|
|
function _WP_Script() {
|
|
|
|
@list($this->handle, $this->src, $this->deps, $this->ver) = func_get_args();
|
|
|
|
if ( !is_array($this->deps) )
|
|
|
|
$this->deps = array();
|
|
|
|
if ( !$this->ver )
|
|
|
|
$this->ver = false;
|
|
|
|
}
|
2007-03-06 01:39:46 +01:00
|
|
|
|
|
|
|
function localize( $object_name, $l10n ) {
|
|
|
|
if ( !$object_name || !is_array($l10n) )
|
|
|
|
return false;
|
|
|
|
$this->l10n_object = $object_name;
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
return true;
|
|
|
|
}
|
2006-05-22 19:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints script tags in document head
|
|
|
|
*
|
|
|
|
* Called by admin-header.php and by wp_head hook. Since it is called by wp_head on every page load,
|
|
|
|
* the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
|
|
|
|
* Does make use of already instantiated $wp_scripts if present.
|
|
|
|
* Use provided wp_print_scripts hook to register/enqueue new scripts.
|
|
|
|
*
|
|
|
|
* @see WP_Scripts::print_scripts()
|
|
|
|
*/
|
|
|
|
function wp_print_scripts( $handles = false ) {
|
|
|
|
do_action( 'wp_print_scripts' );
|
2006-08-18 07:23:41 +02:00
|
|
|
if ( '' === $handles ) // for wp_head
|
|
|
|
$handles = false;
|
2006-05-22 19:16:05 +02:00
|
|
|
|
|
|
|
global $wp_scripts;
|
|
|
|
if ( !is_a($wp_scripts, 'WP_Scripts') ) {
|
|
|
|
if ( !$handles )
|
|
|
|
return array(); // No need to instantiate if nothing's there.
|
|
|
|
else
|
|
|
|
$wp_scripts = new WP_Scripts();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $wp_scripts->print_scripts( $handles );
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
|
|
|
|
global $wp_scripts;
|
|
|
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
|
|
|
$wp_scripts = new WP_Scripts();
|
|
|
|
|
|
|
|
$wp_scripts->add( $handle, $src, $deps, $ver );
|
|
|
|
}
|
|
|
|
|
2007-03-06 01:39:46 +01:00
|
|
|
/**
|
|
|
|
* Localizes a script
|
|
|
|
*
|
|
|
|
* Localizes only if script has already been added
|
|
|
|
*
|
|
|
|
* @see WP_Script::localize()
|
|
|
|
*/
|
|
|
|
function wp_localize_script( $handle, $object_name, $l10n ) {
|
|
|
|
global $wp_scripts;
|
|
|
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return $wp_scripts->localize( $handle, $object_name, $l10n );
|
|
|
|
}
|
|
|
|
|
2006-05-22 19:16:05 +02:00
|
|
|
function wp_deregister_script( $handle ) {
|
|
|
|
global $wp_scripts;
|
|
|
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
|
|
|
$wp_scripts = new WP_Scripts();
|
|
|
|
|
|
|
|
$wp_scripts->remove( $handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Equeues script
|
|
|
|
*
|
|
|
|
* Registers the script if src provided (does NOT overwrite) and enqueues.
|
|
|
|
*
|
|
|
|
* @see WP_Script::add(), WP_Script::enqueue()
|
|
|
|
*/
|
|
|
|
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) {
|
|
|
|
global $wp_scripts;
|
|
|
|
if ( !is_a($wp_scripts, 'WP_Scripts') )
|
|
|
|
$wp_scripts = new WP_Scripts();
|
|
|
|
|
|
|
|
if ( $src ) {
|
|
|
|
$_handle = explode('?', $handle);
|
|
|
|
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
|
|
|
|
}
|
|
|
|
$wp_scripts->enqueue( $handle );
|
|
|
|
}
|
2007-10-09 23:04:26 +02:00
|
|
|
|
|
|
|
function wp_prototype_before_jquery( $js_array ) {
|
|
|
|
if ( false === $jquery = array_search( 'jquery', $js_array ) )
|
|
|
|
return $js_array;
|
|
|
|
|
|
|
|
if ( false === $prototype = array_search( 'prototype', $js_array ) )
|
|
|
|
return $js_array;
|
|
|
|
|
|
|
|
if ( $prototype < $jquery )
|
|
|
|
return $js_array;
|
|
|
|
|
|
|
|
unset($js_array[$prototype]);
|
|
|
|
|
|
|
|
array_splice( $js_array, $jquery, 0, 'prototype' );
|
|
|
|
|
|
|
|
return $js_array;
|
|
|
|
}
|
|
|
|
|
2008-02-22 05:02:09 +01:00
|
|
|
// These localizations require information that may not be loaded even by init
|
|
|
|
function wp_just_in_time_script_localization() {
|
|
|
|
wp_localize_script( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
|
2007-10-09 23:04:26 +02:00
|
|
|
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
|
|
|
|
|
2008-02-21 07:19:46 +01:00
|
|
|
?>
|