[wp-trac] [WordPress Trac] #36774: Wrong JQuery UI AMD support
WordPress Trac
noreply at wordpress.org
Fri May 6 09:18:50 UTC 2016
#36774: Wrong JQuery UI AMD support
----------------------------+------------------------------
Reporter: Andrei Kazakou | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.5.1
Severity: normal | Resolution:
Keywords: | Focuses:
----------------------------+------------------------------
Comment (by Andrei Kazakou):
I catched this problem, when i tryed integrate Visual Composer plugin into
my own theme with RequireJS. It means, whn i try open Frontend Editor from
VC plugin, it trying load UI plugins from existing theme. My code catch
all wp_enque_script calls and generate RequireJS config for loading
javascript files.
{{{#!php
<?php
/**
* That class provide functional for difficult theme settings
*
* @author Andrey Kazakov <akazakou at exadel.com>
*/
class ThemeSettings {
/**
* Instance of current class
* @var \ThemeSettings
*/
protected static $_instance;
/**
* Containd describe for RequireJS configuration
* @var array[]
*/
protected $_scripts = array();
/**
* Disallow native creation of object
*/
protected function __construct() {}
/**
* Generate and return instance of current class
* @return \ThemeSettings
*/
public static function getInstance() {
if (empty(self::$_instance)) {
self::$_instance = new ThemeSettings();
}
return self::$_instance;
}
/**
* Add describe of javascript to RequireJS config
* @param string $handle
* @param string[] $script
*/
public function addScript($handle, $script) {
$this->_scripts[$handle] = $script;
}
/**
* Generate config for RequireJS loader
* @return stdClass
*/
public function getRequirejsConfig() {
$config = (object) array('waitSeconds' => 30,'paths' => (object)
array(), 'shim' => (object) array());
foreach ($this->_scripts as $handle => $script) {
$config->paths->{$handle} = $script->src;
if (!empty($script->deps)) {
$config->shim->{$handle} = $script->deps;
}
switch($handle) {
case 'admin-bar':
$config->shim->{$handle} = array('jquery');
break;
}
}
return $config;
}
/**
* Get all JS scripts description
* @return type
*/
function getScripts() {
return $this->_scripts;
}
}
/* Delayed loading of all JS files */
add_filter('script_loader_tag', function($tag, $handle, $src) {
if (isAdmin()) return $tag;
global $wp_scripts;
ThemeSettings::getInstance()->addScript($handle, (object)array(
'deps' => $wp_scripts->query($handle, 'registered')->deps,
'src' => $src,
'tag' => $tag
));
return '';
}, 10, 3);
}}}
But when i catch standart the JQuery UI scripts, it try load modules with
RequireJS supports and can't find these modules.
I propose to you recompile JQuery UI files with naming modules like it
named in WordPress.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36774#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list