Skip to content

Commit b898d4a

Browse files
committed
Superbundle css file for front-office with Font Awesome and Bootstrap
1 parent b61cf35 commit b898d4a

18 files changed

Lines changed: 15126 additions & 67 deletions

File tree

Gruntfile.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ module.exports = function(grunt) {
4343
'rsc/less/bootstrap-evoskins.less' // Common styles for all bootstrap skins
4444
],
4545

46+
// Superbundle Font-Awesome + Bootstrap + Front-office styles:
47+
'rsc/build/bootstrap-b2evo_base-superbundle.bundle.css': [
48+
'rsc/css/font-awesome.css',
49+
'rsc/css/bootstrap/bootstrap.css',
50+
'rsc/build/bootstrap-b2evo_base.bundle.css',
51+
],
52+
4653
// Bootstrap back-office styles:
4754
'rsc/build/bootstrap-backoffice-b2evo_base.bundle.css': [
4855
// Basic styles for all bootstrap skins
@@ -157,6 +164,11 @@ module.exports = function(grunt) {
157164
src: 'rsc/build/bootstrap-b2evo_base.bundle.css',
158165
dest: 'rsc/build/bootstrap-b2evo_base.bmin.css',
159166
},
167+
bootstrap_b2evo_base_superbundle: {
168+
nonull: true, // Display missing files
169+
src: 'rsc/build/bootstrap-b2evo_base-superbundle.bundle.css',
170+
dest: 'rsc/build/bootstrap-b2evo_base-superbundle.bmin.css',
171+
},
160172
bootstrap_backoffice_b2evo_base: {
161173
nonull: true, // Display missing files
162174
src: 'rsc/build/bootstrap-backoffice-b2evo_base.bundle.css',

conf/_advanced.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,16 +953,26 @@
953953
);
954954

955955
/**
956-
* JS files which contain other JS files in order to don't required them twice when main file is required on current page
956+
* JS/CSS files which contain other JS/CSS files in order to don't required them twice when main file is required on current page
957957
*
958-
* Key - Alias or relative path of main JS file, Value - array of bundled files inside the main JS file
958+
* Key - Alias or relative path of main JS/CSS file, Value - array of bundled files inside the main JS/CSS file
959959
*/
960-
$bundled_js_files = array(
960+
$bundled_files = array(
961961
'build/bootstrap-evo_frontoffice-superbundle.bmin.js' => array(
962962
'#jquery#',
963963
'#jquery_migrate#',
964964
'#bootstrap#',
965965
),
966+
'bootstrap-b2evo_base-superbundle.bundle.css' => array(
967+
'#fontawesome#',
968+
'#bootstrap_css#',
969+
'bootstrap-b2evo_base.bundle.css',
970+
),
971+
'bootstrap-b2evo_base-superbundle.bmin.css' => array(
972+
'#fontawesome#',
973+
'#bootstrap_css#',
974+
'bootstrap-b2evo_base.bmin.css',
975+
),
966976
);
967977

968978
/**

conf/_application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Release date (ISO)
2222
* @global string
2323
*/
24-
$app_date = '2020-06-15';
24+
$app_date = '2020-06-17';
2525

2626
/**
2727
* Is this b2evolution PRO?

inc/_core/_template.funcs.php

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,56 @@ function get_require_url( $lib_file, $relative_to = 'rsc_url', $subfolder = 'js'
12571257
return $lib_url;
12581258
}
12591259

1260+
1261+
/**
1262+
* Check if the requested file is bundled in another
1263+
*
1264+
* @param string alias, url or filename (relative to rsc/js) for javascript file
1265+
* @param boolean|string Is the file's path relative to the base path/url?
1266+
* @param string 'js' or 'css' or 'build'
1267+
* @param string version number to append at the end of requested url to avoid getting an old version from the cache
1268+
* @return integer Index of first file that was dequeued because it is bundled inside current requested file
1269+
*/
1270+
function check_bundled_file( $file, $relative_to = 'rsc_url', $subfolder = 'js', $version = '#' )
1271+
{
1272+
global $required_js, $required_css, $bundled_files;
1273+
1274+
// Store here index of first file that was dequeued because it is bundled inside current requested file:
1275+
$first_dequeued_file_index = NULL;
1276+
1277+
if( isset( $bundled_files[ $file ] ) )
1278+
{ // If currently required file contains other JS files which must not be required twice:
1279+
foreach( $bundled_files[ $file ] as $bundled_file )
1280+
{ // Include all bundled files in the global array in order to don't call them twice:
1281+
$bundled_url = strtolower( get_require_url( $bundled_file, $relative_to, $subfolder, $version ) );
1282+
if( $subfolder == 'js' )
1283+
{ // JS file:
1284+
if( empty( $required_js ) || ! in_array( $bundled_url, $required_js ) )
1285+
{ // Include bundled file into this global array in order to don't require this if it will be required further:
1286+
$required_js[] = $bundled_url;
1287+
}
1288+
}
1289+
else // 'css' or 'build'
1290+
{ // CSS file:
1291+
if( empty( $required_css ) || ! in_array( $bundled_url, $required_css ) )
1292+
{ // Include bundled file into this global array in order to don't require this if it will be required further:
1293+
$required_css[] = $bundled_url;
1294+
}
1295+
}
1296+
// Dequeue the file if it was required before:
1297+
$dequeued_file_index = dequeue( $bundled_file, $relative_to );
1298+
if( $first_dequeued_file_index === NULL )
1299+
{ // We need to know first dequeued file in order to insert currently
1300+
// required file in that place instead of insert it as last ordered:
1301+
$first_dequeued_file_index = $dequeued_file_index;
1302+
}
1303+
}
1304+
}
1305+
1306+
return $first_dequeued_file_index;
1307+
}
1308+
1309+
12601310
/**
12611311
* Memorize that a specific javascript file will be required by the current page.
12621312
* All requested files will be included in the page head only once (when headlines is called)
@@ -1276,8 +1326,8 @@ function get_require_url( $lib_file, $relative_to = 'rsc_url', $subfolder = 'js'
12761326
*/
12771327
function require_js( $js_file, $relative_to = 'rsc_url', $async_defer = false, $output = false, $version = '#', $position = 'headlines' )
12781328
{
1279-
global $required_js; // Use this var as global and NOT static, because it is used in other functions(e.g. display_ajax_form())
1280-
global $use_defer, $bundled_js_files;
1329+
global $required_js; // Use this var as global and NOT static, because it is used in other functions(e.g. display_ajax_form(), check_bundled_file())
1330+
global $use_defer;
12811331

12821332
if( is_admin_page() && in_array( $js_file, array( 'functions.js', 'ajax.js', 'form_extensions.js', 'extracats.js', 'dynamic_select.js', 'backoffice.js' ) ) )
12831333
{ // Don't require this file on back-office because it is auto loaded by bundled file evo_backoffice.bmin.js:
@@ -1289,27 +1339,8 @@ function require_js( $js_file, $relative_to = 'rsc_url', $async_defer = false, $
12891339
return;
12901340
}
12911341

1292-
// Store here index of first file that was dequeued because it is bundled inside current requested file:
1293-
$first_dequeued_file_index = NULL;
1294-
1295-
if( isset( $bundled_js_files[ $js_file ] ) )
1296-
{ // If currently required file contains other JS files which must not be required twice:
1297-
foreach( $bundled_js_files[ $js_file ] as $bundled_js_file )
1298-
{ // Include all bundled files in the global array in order to don't call them twice:
1299-
$bundled_js_url = strtolower( get_require_url( $bundled_js_file, $relative_to, 'js', $version ) );
1300-
if( empty( $required_js ) || ! in_array( $bundled_js_url, $required_js ) )
1301-
{ // Include bundled file into this global array in order to don't require this if it will be required further:
1302-
$required_js[] = $bundled_js_url;
1303-
}
1304-
// Dequeue the file if it was required before:
1305-
$dequeued_file_index = dequeue( $bundled_js_file, $relative_to );
1306-
if( $first_dequeued_file_index === NULL )
1307-
{ // We need to know first dequeued file in order to insert currently
1308-
// required file in that place instead of insert it as last ordered:
1309-
$first_dequeued_file_index = $dequeued_file_index;
1310-
}
1311-
}
1312-
}
1342+
// Get index of first file that was dequeued because it is bundled inside current requested file:
1343+
$first_dequeued_file_index = check_bundled_file( $js_file, $relative_to, 'js', $version );
13131344

13141345
if( in_array( $js_file, array( '#jqueryUI#', 'communication.js', 'functions.js' ) ) )
13151346
{ // Dependency : ensure jQuery is loaded
@@ -1413,7 +1444,7 @@ function require_js_defer( $js_file, $relative_to = 'rsc_url', $output = false,
14131444
*/
14141445
function require_css( $css_file, $relative_to = 'rsc_url', $title = NULL, $media = NULL, $version = '#', $output = false, $position = 'headlines', $async = false )
14151446
{
1416-
static $required_css;
1447+
global $required_css; // Use this var as global and NOT static, because it is used in other functions(e.g. check_bundled_file())
14171448

14181449
// Which subfolder do we want to use in case of absolute paths? (doesn't appy to 'relative')
14191450
$subfolder = 'css';
@@ -1425,6 +1456,14 @@ function require_css( $css_file, $relative_to = 'rsc_url', $title = NULL, $media
14251456
}
14261457
}
14271458

1459+
if( is_dequeued( $css_file, $relative_to ) )
1460+
{ // Don't require if the file was already dequeued once:
1461+
return;
1462+
}
1463+
1464+
// Get index of first file that was dequeued because it is bundled inside current requested file:
1465+
$first_dequeued_file_index = check_bundled_file( $css_file, $relative_to, $subfolder, $version );
1466+
14281467
// Get library url of CSS file by alias name
14291468
$css_url = get_require_url( $css_file, $relative_to, $subfolder, $version );
14301469

@@ -1462,11 +1501,11 @@ function require_css( $css_file, $relative_to = 'rsc_url', $title = NULL, $media
14621501
{ // Add stylesheet tag to <head>
14631502
if($position == 'headlines' )
14641503
{
1465-
add_headline( $stylesheet_tag, $css_file, $relative_to );
1504+
add_headline( $stylesheet_tag, $css_file, $relative_to, $first_dequeued_file_index );
14661505
}
14671506
elseif( $position == 'footerlines' )
14681507
{
1469-
add_footerline( $stylesheet_tag, $css_file, $relative_to );
1508+
add_footerline( $stylesheet_tag, $css_file, $relative_to, $first_dequeued_file_index );
14701509
}
14711510
}
14721511
}
@@ -3772,16 +3811,19 @@ function get_prevent_key_enter_js( $jquery_selection )
37723811
* - 'fontawesome' - Use only font-awesome icons
37733812
* - 'fontawesome-glyphicons' - Use font-awesome icons as a priority over the glyphicons
37743813
* @param boolean|string 'relative' or true (relative to <base>) or 'rsc_url' (relative to $rsc_url) or 'blog' (relative to current blog URL -- may be subdomain or custom domain)
3814+
* @param boolean TRUE - to require css file, FALSE - is used when css file is already loaded inside superbundle file
37753815
*/
3776-
function init_fontawesome_icons( $icons_type = 'fontawesome', $relative_to = 'rsc_url' )
3816+
function init_fontawesome_icons( $icons_type = 'fontawesome', $relative_to = 'rsc_url', $require_files = true )
37773817
{
37783818
global $b2evo_icons_type;
37793819

37803820
// Use font-awesome icons, @see get_icon()
37813821
$b2evo_icons_type = $icons_type;
37823822

3783-
// Load main CSS file of font-awesome icons
3784-
require_css( '#fontawesome#', $relative_to );
3823+
if( $require_files )
3824+
{ // Load main CSS file of font-awesome icons
3825+
require_css( '#fontawesome#', $relative_to );
3826+
}
37853827
}
37863828

37873829

inc/skins/model/_skin.class.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,25 @@ function display_init( /*optional: $features = array() */ )
13551355
case 'superbundle':
13561356
// Include jQuery + Bootstrap + General front-office scripts:
13571357
require_js_defer( 'build/bootstrap-evo_frontoffice-superbundle.bmin.js', 'blog' );
1358+
// Initialize font-awesome icons and use them as a priority over the glyphicons, @see get_icon()
1359+
init_fontawesome_icons( 'fontawesome-glyphicons', 'blog', false /* Don't load CSS file because it is bundled */ );
1360+
// Include the bootstrap-b2evo_base CSS (NEW / v6 style) - Use this when you use Bootstrap:
1361+
if( $debug )
1362+
{ // Use readable CSS:
1363+
// rsc/css/font-awesome.css
1364+
// rsc/css/bootstrap/bootstrap.css
1365+
// rsc/build/bootstrap-b2evo_base.bundle.css:
1366+
// - rsc/less/bootstrap-basic_styles.less
1367+
// - rsc/less/bootstrap-basic.less
1368+
// - rsc/less/bootstrap-blog_base.less
1369+
// - rsc/less/bootstrap-item_base.less
1370+
// - rsc/less/bootstrap-evoskins.less
1371+
require_css( 'bootstrap-b2evo_base-superbundle.bundle.css', 'blog' ); // CSS concatenation of the above
1372+
}
1373+
else
1374+
{ // Use minified CSS:
1375+
require_css( 'bootstrap-b2evo_base-superbundle.bmin.css', 'blog' ); // Concatenation + Minifaction of the above
1376+
}
13581377
break;
13591378

13601379
case 'jquery':
@@ -1375,8 +1394,8 @@ function display_init( /*optional: $features = array() */ )
13751394
if( ! in_array( 'superbundle', $features ) )
13761395
{ // Don't include when it is already bundled:
13771396
require_js_defer( '#bootstrap#', 'blog' );
1397+
require_css( '#bootstrap_css#', 'blog' );
13781398
}
1379-
require_css( '#bootstrap_css#', 'blog' );
13801399
break;
13811400

13821401
case 'bootstrap_theme_css':
@@ -1385,6 +1404,10 @@ function display_init( /*optional: $features = array() */ )
13851404
break;
13861405

13871406
case 'bootstrap_evo_css':
1407+
if( in_array( 'superbundle', $features ) )
1408+
{ // Don't include when it is already bundled:
1409+
break;
1410+
}
13881411
// Include the bootstrap-b2evo_base CSS (NEW / v6 style) - Use this when you use Bootstrap:
13891412
if( $debug )
13901413
{ // Use readable CSS:

rsc/build/bootstrap-b2evo_base-superbundle.bmin.css

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)