mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Script loader from mdawaffe. #2701
git-svn-id: http://svn.automattic.com/wordpress/trunk@3788 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
afc4ec89bd
commit
4d49e98fe4
@ -1173,14 +1173,15 @@ function save_mod_rewrite_rules() {
|
||||
|
||||
function the_quicktags() {
|
||||
// Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
|
||||
if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Safari'))
|
||||
if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Safari')) {
|
||||
echo '
|
||||
<div id="quicktags">
|
||||
<script src="../wp-includes/js/quicktags.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 ) edToolbar();</script>
|
||||
';
|
||||
wp_print_scripts( 'quicktags' );
|
||||
echo ' <script type="text/javascript">if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 ) edToolbar();</script>
|
||||
</div>
|
||||
';
|
||||
else echo '
|
||||
} else echo '
|
||||
<script type="text/javascript">
|
||||
function edInsertContent(myField, myValue) {
|
||||
//IE support
|
||||
|
@ -2,17 +2,15 @@
|
||||
@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
|
||||
if (!isset($_GET["page"])) require_once('admin.php');
|
||||
if ( $editing ) {
|
||||
$dbx_js = true;
|
||||
$pmeta_js = true;
|
||||
$list_js = true;
|
||||
if ( current_user_can('manage_categories') ) {
|
||||
$cat_js = true;
|
||||
}
|
||||
wp_enqueue_script( array("dbx-admin-key?pagenow=$pagenow",'admin-custom-fields') );
|
||||
if ( current_user_can('manage_categories') )
|
||||
wp_enqueue_script( 'ajaxcat' );
|
||||
if ( user_can_richedit() )
|
||||
wp_enqueue_script( 'wp_tiny_mce' );
|
||||
}
|
||||
if ( $list_js )
|
||||
$sack_js = true;
|
||||
|
||||
get_admin_page_title();
|
||||
?>
|
||||
<?php get_admin_page_title(); ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
@ -24,53 +22,9 @@ if ( $list_js )
|
||||
function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
|
||||
//]]>
|
||||
</script>
|
||||
<script type="text/javascript" src="../wp-includes/js/fat.js"></script>
|
||||
<?php if ( $xfn_js ) { ?>
|
||||
<script type="text/javascript" src="xfn.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( $sack_js ) { ?>
|
||||
<script type="text/javascript" src="../wp-includes/js/tw-sack.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( $list_js ) { ?>
|
||||
<script type="text/javascript" src="list-manipulation-js.php"></script>
|
||||
<?php } ?>
|
||||
<?php if ( $pmeta_js ) { ?>
|
||||
<script type="text/javascript" src="custom-fields.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( 'categories.php' == $pagenow && 'edit' != $action ) { ?>
|
||||
<script type="text/javascript" src="categories.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( $users_js ) { ?>
|
||||
<script type="text/javascript" src="users.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( 'edit-comments.php' == $pagenow || ( 'edit.php' == $pagenow && 1 == $_GET['c'] ) ) { ?>
|
||||
<script type="text/javascript" src="edit-comments.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( $dbx_js ) { ?>
|
||||
<script type="text/javascript" src="../wp-includes/js/dbx.js"></script>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
addLoadEvent( function() {
|
||||
<?php switch ( $pagenow ) : case 'post.php' : case 'post-new.php' : ?>
|
||||
var manager = new dbxManager('postmeta');
|
||||
<?php break; case 'page.php' : case 'page-new.php' : ?>
|
||||
var manager = new dbxManager('pagemeta');
|
||||
<?php break; case 'link.php' : case 'link-add.php' : ?>
|
||||
var manager = new dbxManager('linkmeta');
|
||||
<?php break; endswitch; ?>
|
||||
});
|
||||
//]]>
|
||||
</script>
|
||||
<script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script>
|
||||
<?php } ?>
|
||||
<?php if ( $editing && user_can_richedit() ) { tinymce_include(); } ?>
|
||||
<?php if ( $cat_js ) { ?>
|
||||
<script type="text/javascript" src="cat-js.php"></script>
|
||||
<?php } ?>
|
||||
<?php if ( ($parent_file != 'link-manager.php') && ($parent_file != 'options-general.php') ) : ?>
|
||||
<style type="text/css">* html { overflow-x: hidden; }</style>
|
||||
<?php endif; ?>
|
||||
<?php do_action('admin_head'); ?>
|
||||
<?php endif; wp_print_scripts(); do_action('admin_head'); ?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wphead">
|
||||
|
@ -40,7 +40,9 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
||||
}
|
||||
}
|
||||
|
||||
$xfn_js = $sack_js = $list_js = $cat_js = $users_js = $dbx_js = $pmeta_js = $editing = false;
|
||||
wp_enqueue_script( 'fat' );
|
||||
|
||||
$editing = false;
|
||||
|
||||
require(ABSPATH . '/wp-admin/menu.php');
|
||||
|
||||
|
@ -79,7 +79,7 @@ break;
|
||||
|
||||
default:
|
||||
|
||||
$list_js = true;
|
||||
wp_enqueue_script( 'admin-categories' );
|
||||
require_once ('admin-header.php');
|
||||
|
||||
$messages[1] = __('Category added.');
|
||||
|
@ -1,5 +1,24 @@
|
||||
<?php
|
||||
require_once('admin.php');
|
||||
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
|
||||
|
||||
switch ( $_GET['pagenow'] ) :
|
||||
case 'post.php' :
|
||||
case 'post-new.php' :
|
||||
$man = 'postmeta';
|
||||
break;
|
||||
case 'page.php' :
|
||||
case 'page-new.php' :
|
||||
$man = 'pagemeta';
|
||||
break;
|
||||
case 'link-add.php' :
|
||||
case 'link.php' :
|
||||
$man = 'linkmeta';
|
||||
break;
|
||||
endswitch;
|
||||
?>
|
||||
addLoadEvent( function() {var manager = new dbxManager('<?php echo $man; ?>');} );
|
||||
|
||||
//initialisation function
|
||||
addLoadEvent( function()
|
||||
{
|
||||
//create new docking boxes group
|
@ -3,7 +3,7 @@ require_once('admin.php');
|
||||
|
||||
$title = __('Edit Comments');
|
||||
$parent_file = 'edit.php';
|
||||
$list_js = true;
|
||||
wp_enqueue_script( 'admin-comments' );
|
||||
|
||||
require_once('admin-header.php');
|
||||
if (empty($_GET['mode'])) $mode = 'view';
|
||||
|
@ -2,7 +2,7 @@
|
||||
require_once('admin.php');
|
||||
$title = __('Pages');
|
||||
$parent_file = 'edit.php';
|
||||
$list_js = true;
|
||||
wp_enqueue_script( 'listman' );
|
||||
require_once('admin-header.php');
|
||||
?>
|
||||
|
||||
|
@ -3,7 +3,7 @@ require_once('admin.php');
|
||||
|
||||
$title = __('Posts');
|
||||
$parent_file = 'edit.php';
|
||||
$list_js = true;
|
||||
wp_enqueue_script( 1 == $_GET['c'] ? 'admin-comments' : 'listman' );
|
||||
require_once('admin-header.php');
|
||||
|
||||
$_GET['m'] = (int) $_GET['m'];
|
||||
|
@ -25,7 +25,7 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
||||
}
|
||||
}
|
||||
|
||||
$xfn_js = true;
|
||||
wp_enqueue_script( 'xfn' );
|
||||
$editing = true;
|
||||
require('admin-header.php');
|
||||
?>
|
||||
|
@ -8,7 +8,7 @@ require_once ('admin.php');
|
||||
|
||||
$title = __('Manage Bookmarks');
|
||||
$this_file = $parent_file = 'link-manager.php';
|
||||
$list_js = true;
|
||||
wp_enqueue_script( 'listman' );
|
||||
|
||||
$wpvarstoreset = array ('action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]');
|
||||
|
||||
|
@ -102,7 +102,7 @@ switch ($action) {
|
||||
break;
|
||||
|
||||
case 'edit' :
|
||||
$xfn_js = true;
|
||||
wp_enqueue_script( 'xfn' );
|
||||
$editing = true;
|
||||
$parent_file = 'link-manager.php';
|
||||
$submenu_file = 'link-manager.php';
|
||||
|
@ -3,7 +3,7 @@ require_once('admin.php');
|
||||
|
||||
$title = __('Moderate comments');
|
||||
$parent_file = 'edit.php';
|
||||
$list_js = true;
|
||||
wp_enqueue_script( 'listman' );
|
||||
|
||||
$wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky');
|
||||
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
||||
|
@ -143,9 +143,7 @@ case 'adduser':
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
$list_js = true;
|
||||
$users_js = true;
|
||||
wp_enqueue_script( 'admin-users' );
|
||||
|
||||
include ('admin-header.php');
|
||||
|
||||
|
@ -86,6 +86,7 @@ add_filter('option_ping_sites', 'privacy_ping_filter');
|
||||
add_action('wp_head', 'rsd_link');
|
||||
add_action('publish_future_post', 'wp_publish_post', 10, 1);
|
||||
add_action('wp_head', 'noindex', 1);
|
||||
add_action('wp_head', 'wp_print_scripts');
|
||||
if(!defined('DOING_CRON'))
|
||||
add_action('init', 'wp_cron');
|
||||
add_action('do_feed_rdf', 'do_feed_rdf', 10, 1);
|
||||
|
@ -452,4 +452,8 @@ function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = '
|
||||
return wp_dropdown_categories($query);
|
||||
}
|
||||
|
||||
// Deprecated. Use wp_print_scripts() or WP_Scripts instead.
|
||||
function tinymce_include() {
|
||||
wp_print_script( 'wp_tiny_mce' );
|
||||
}
|
||||
?>
|
||||
|
@ -1039,18 +1039,6 @@ function do_all_pings() {
|
||||
generic_ping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Places two script links in <head>: one to get tinyMCE (big), one to configure and start it (small)
|
||||
*/
|
||||
function tinymce_include() {
|
||||
$ver = '04162006';
|
||||
$src1 = get_settings('siteurl') . "/wp-includes/js/tinymce/tiny_mce_gzip.php?ver=$ver";
|
||||
$src2 = get_settings('siteurl') . "/wp-includes/js/tinymce/tiny_mce_config.php?ver=$ver";
|
||||
|
||||
echo "<script type='text/javascript' src='$src1'></script>\n";
|
||||
echo "<script type='text/javascript' src='$src2'></script>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Places a textarea according to the current user's preferences, filled with $content.
|
||||
* Also places a script block that enables tabbing between Title and Content.
|
||||
|
235
wp-includes/script-loader.php
Normal file
235
wp-includes/script-loader.php
Normal file
@ -0,0 +1,235 @@
|
||||
<?php
|
||||
class WP_Scripts {
|
||||
var $scripts = array();
|
||||
var $queue = array();
|
||||
var $printed = array();
|
||||
var $args = array();
|
||||
|
||||
function WP_Scripts() {
|
||||
$this->default_scripts();
|
||||
}
|
||||
|
||||
function default_scripts() {
|
||||
$this->add( 'dbx', '/wp-includes/js/dbx.js', false, '2.02' );
|
||||
$this->add( 'fat', '/wp-includes/js/fat.js', false, '1.0-RC1_3660' );
|
||||
$this->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' );
|
||||
$this->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3517' );
|
||||
$this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', false, '3517' );
|
||||
$this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_gzip.php', false, '04162006' );
|
||||
$this->add( 'wp_tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('tiny_mce'), '04162006' );
|
||||
if ( is_admin() ) {
|
||||
$this->add( 'dbx-admin-key', '/wp-admin/dbx-admin-key-js.php', array('dbx'), '3651' );
|
||||
$this->add( 'listman', '/wp-admin/list-manipulation-js.php', array('sack', 'fat'), '3733' );
|
||||
$this->add( 'ajaxcat', '/wp-admin/cat-js.php', array('listman'), '3684' );
|
||||
$this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' );
|
||||
$this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' );
|
||||
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3736' );
|
||||
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '3684' );
|
||||
$this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) {
|
||||
// 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;
|
||||
$handles = $this->all_deps( $handles );
|
||||
$this->_print_scripts( $handles );
|
||||
return $this->printed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internally used helper function for printing script tags
|
||||
*
|
||||
* @param array handles Hierarchical array of scripts to be printed
|
||||
* @see WP_Scripts::all_deps()
|
||||
*/
|
||||
function _print_scripts( $handles ) {
|
||||
global $wp_db_version;
|
||||
|
||||
foreach( array_keys($handles) as $handle ) {
|
||||
if ( !$handles[$handle] )
|
||||
return;
|
||||
elseif ( is_array($handles[$handle]) )
|
||||
$this->_print_scripts( $handles[$handle] );
|
||||
if ( !in_array($handle, $this->printed) && isset($this->scripts[$handle]) ) {
|
||||
$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_settings( 'siteurl' ) . $this->scripts[$handle]->src;
|
||||
echo "<script type='text/javascript' src='$src?ver=$ver'></script>\n";
|
||||
$this->printed[] = $handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines dependencies of scripts
|
||||
*
|
||||
* Recursively builds hierarchical array of script dependencies. Does NOT catch infinite loops.
|
||||
*
|
||||
* @param mixed handles Accepts (string) script name or (array of strings) script names
|
||||
* @param bool recursion Used internally when function calls itself
|
||||
* @return array Hierarchical array of dependencies
|
||||
*/
|
||||
function all_deps( $handles, $recursion = false ) {
|
||||
if ( ! $handles = (array) $handles )
|
||||
return array();
|
||||
$return = array();
|
||||
foreach ( $handles as $handle ) {
|
||||
$handle = explode('?', $handle);
|
||||
if ( isset($handle[1]) )
|
||||
$this->args[$handle[0]] = $handle[1];
|
||||
$handle = $handle[0];
|
||||
if ( is_null($return[$handle]) ) // Prime the return array with $handles
|
||||
$return[$handle] = true;
|
||||
if ( $this->scripts[$handle]->deps ) {
|
||||
if ( false !== $return[$handle] && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) )
|
||||
$return[$handle] = false; // Script required deps which don't exist
|
||||
else
|
||||
$return[$handle] = $this->all_deps( $this->scripts[$handle]->deps, true ); // Build the hierarchy
|
||||
}
|
||||
if ( $recursion && false === $return[$handle] )
|
||||
return false; // Cut the branch
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class _WP_Script {
|
||||
var $handle;
|
||||
var $src;
|
||||
var $deps = array();
|
||||
var $ver = false;
|
||||
var $args = false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
?>
|
@ -143,6 +143,7 @@ require (ABSPATH . WPINC . '/kses.php');
|
||||
require (ABSPATH . WPINC . '/cron.php');
|
||||
require (ABSPATH . WPINC . '/version.php');
|
||||
require (ABSPATH . WPINC . '/deprecated.php');
|
||||
require (ABSPATH . WPINC . '/script-loader.php');
|
||||
|
||||
if (!strstr($_SERVER['PHP_SELF'], 'install.php')) :
|
||||
// Used to guarantee unique hash cookies
|
||||
|
Loading…
Reference in New Issue
Block a user