mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allow Requirements::add_i18n_javascript() to return its files more optimised inclusion, using it in LeftAndMain
This commit is contained in:
parent
fcc01a322b
commit
a633326c3e
@ -222,6 +222,11 @@ class LeftAndMain extends Controller {
|
||||
$htmlEditorConfig->setOption('content_css', implode(',', $cssFiles));
|
||||
}
|
||||
|
||||
// Using uncompressed files as they'll be processed by JSMin in the Requirements class.
|
||||
// Not as effective as other compressors or pre-compressed+finetuned files,
|
||||
// but overall the unified minification into a single file brings more performance benefits
|
||||
// than a couple of saved bytes (after gzip) in individual files.
|
||||
// We also re-compress already compressed files through JSMin as this causes weird runtime bugs.
|
||||
Requirements::combine_files(
|
||||
'lib.js',
|
||||
array(
|
||||
@ -266,23 +271,24 @@ class LeftAndMain extends Controller {
|
||||
|
||||
Requirements::combine_files(
|
||||
'leftandmain.js',
|
||||
array(
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Content.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.AddForm.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Preview.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.BatchActions.js',
|
||||
)
|
||||
array_unique(array_merge(
|
||||
array(
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Content.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.AddForm.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Preview.js',
|
||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.BatchActions.js',
|
||||
),
|
||||
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang', true, true),
|
||||
Requirements::add_i18n_javascript(SAPPHIRE_ADMIN_DIR . '/javascript/lang', true, true)
|
||||
))
|
||||
);
|
||||
|
||||
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
|
||||
Requirements::add_i18n_javascript(SAPPHIRE_ADMIN_DIR . '/javascript/lang');
|
||||
|
||||
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
|
||||
Requirements::css(SAPPHIRE_ADMIN_DIR .'/thirdparty/chosen/chosen/chosen.css');
|
||||
Requirements::css(THIRDPARTY_DIR . '/jstree/themes/apple/style.css');
|
||||
|
6
admin/javascript/lang/en_US.js
Normal file
6
admin/javascript/lang/en_US.js
Normal file
@ -0,0 +1,6 @@
|
||||
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
|
||||
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
|
||||
} else {
|
||||
ss.i18n.addDictionary('en_US', {
|
||||
});
|
||||
}
|
@ -228,12 +228,15 @@ class Requirements {
|
||||
|
||||
/**
|
||||
* Add i18n files from the given javascript directory.
|
||||
* @param $langDir The javascript lang directory, relative to the site root, e.g., 'sapphire/javascript/lang'
|
||||
*
|
||||
* @param String
|
||||
* @param Boolean
|
||||
* @param Boolean
|
||||
*
|
||||
* See {@link Requirements_Backend::add_i18n_javascript()} for more information.
|
||||
*/
|
||||
public static function add_i18n_javascript($langDir) {
|
||||
return self::backend()->add_i18n_javascript($langDir);
|
||||
public static function add_i18n_javascript($langDir, $return = false, $langOnly = false) {
|
||||
return self::backend()->add_i18n_javascript($langDir, $return, $langOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -739,23 +742,33 @@ class Requirements_Backend {
|
||||
/**
|
||||
* Add i18n files from the given javascript directory. Sapphire expects that the given directory
|
||||
* will contain a number of java script files named by language: en_US.js, de_DE.js, etc.
|
||||
* @param $langDir The javascript lang directory, relative to the site root, e.g., 'sapphire/javascript/lang'
|
||||
*
|
||||
* @param String The javascript lang directory, relative to the site root, e.g., 'sapphire/javascript/lang'
|
||||
* @param Boolean Return all relative file paths rather than including them in requirements
|
||||
* @param Boolean Only include language files, not the base libraries
|
||||
*/
|
||||
public function add_i18n_javascript($langDir) {
|
||||
public function add_i18n_javascript($langDir, $return = false, $langOnly = false) {
|
||||
$files = array();
|
||||
if(i18n::get_js_i18n()) {
|
||||
// Include i18n.js even if no languages are found. The fact that
|
||||
// add_i18n_javascript() was called indicates that the methods in
|
||||
// here are needed.
|
||||
$this->javascript(SAPPHIRE_DIR . '/javascript/i18n.js');
|
||||
if(!$langOnly) $files[] = SAPPHIRE_DIR . '/javascript/i18n.js';
|
||||
|
||||
if(substr($langDir,-1) != '/') $langDir .= '/';
|
||||
|
||||
$this->javascript($langDir . i18n::default_locale() . '.js');
|
||||
$this->javascript($langDir . i18n::get_locale() . '.js');
|
||||
$files[] = $langDir . i18n::default_locale() . '.js';
|
||||
$files[] = $langDir . i18n::get_locale() . '.js';
|
||||
|
||||
// Stub i18n implementation for when i18n is disabled.
|
||||
} else {
|
||||
$this->javascript[SAPPHIRE_DIR . '/javascript/i18nx.js'] = true;
|
||||
if(!$langOnly) $files[] = SAPPHIRE_DIR . '/javascript/i18nx.js';
|
||||
}
|
||||
|
||||
if($return) {
|
||||
return $files;
|
||||
} else {
|
||||
foreach($files as $file) $this->javascript($file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -848,7 +861,6 @@ class Requirements_Backend {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($files as $index=>$file) {
|
||||
if(is_array($file)) {
|
||||
// Either associative array path=>path type=>type or numeric 0=>path 1=>type
|
||||
@ -887,7 +899,6 @@ class Requirements_Backend {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->combine_files[$combinedFileName] = $files;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user