forked from Snck3rs/contao-leaflet-maps
Simplify assets configuration.
This commit is contained in:
@@ -160,39 +160,32 @@ require_once TL_ROOT . '/system/modules/leaflet/config/leaflet_providers.php';
|
||||
* - url: An valid url.
|
||||
* - file: An file path relative to the Contao Root.
|
||||
* - source: Inline css/javascript.
|
||||
*
|
||||
* You don't have to define it as array if you simply add a file. Do not add |static and or media type flag to it.
|
||||
* It's getting added by default if not being in debug mode.
|
||||
*/
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet'] = array(
|
||||
'css' => array(
|
||||
array('assets/leaflet/libs/leaflet/leaflet.css', 'file')
|
||||
$GLOBALS['LEAFLET_ASSETS'] = array
|
||||
(
|
||||
'leaflet' => array
|
||||
(
|
||||
'css' => 'assets/leaflet/libs/leaflet/leaflet.css',
|
||||
'javascript' => 'assets/leaflet/libs/leaflet/leaflet.js'
|
||||
),
|
||||
'javascript' => array(
|
||||
array('assets/leaflet/libs/leaflet/leaflet.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet-providers'] = array(
|
||||
'javascript' => array(
|
||||
array('assets/leaflet/libs/leaflet-providers/leaflet-providers.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet-ajax'] = array(
|
||||
'javascript' => array(
|
||||
array('assets/leaflet/libs/leaflet-ajax/leaflet.ajax.min.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet-loading'] = array(
|
||||
'css' => array(
|
||||
array('assets/leaflet/libs/leaflet-loading/Control.Loading.css', 'file')
|
||||
'leaflet-providers' => array
|
||||
(
|
||||
'javascript' => 'assets/leaflet/libs/leaflet-providers/leaflet-providers.js'
|
||||
),
|
||||
'javascript' => array(
|
||||
array('assets/leaflet/libs/leaflet-loading/Control.Loading.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['LEAFLET_ASSETS']['spin.js'] = array(
|
||||
'javascript' => array(
|
||||
array('assets/leaflet/libs/spin-js/spin.min.js', 'file')
|
||||
'leaflet-ajax' => array
|
||||
(
|
||||
'javascript' => 'assets/leaflet/libs/leaflet-ajax/leaflet.ajax.min.js'
|
||||
),
|
||||
'leaflet-loading' => array
|
||||
(
|
||||
'css' => 'assets/leaflet/libs/leaflet-loading/Control.Loading.css',
|
||||
'javascript' => 'assets/leaflet/libs/leaflet-loading/Control.Loading.js'
|
||||
),
|
||||
'spin.js' => array
|
||||
(
|
||||
'javascript' => 'assets/leaflet/libs/spin-js/spin.min.js'
|
||||
)
|
||||
);
|
||||
|
||||
@@ -35,7 +35,10 @@ class ContaoAssets implements Assets
|
||||
break;
|
||||
|
||||
case static::TYPE_FILE:
|
||||
$script .= '|static';
|
||||
if (!\Config::get('debugMode')) {
|
||||
$script .= '|static';
|
||||
}
|
||||
|
||||
// no break
|
||||
|
||||
default:
|
||||
@@ -54,7 +57,9 @@ class ContaoAssets implements Assets
|
||||
break;
|
||||
|
||||
case static::TYPE_FILE:
|
||||
$stylesheet .= '|all|static';
|
||||
if (!\Config::get('debugMode')) {
|
||||
$stylesheet .= '|all|static';
|
||||
}
|
||||
// no break
|
||||
|
||||
default:
|
||||
|
||||
@@ -18,9 +18,8 @@ use Netzmacht\Contao\Leaflet\Event\InitializeEventDispatcherEvent;
|
||||
use Netzmacht\Contao\Leaflet\Event\InitializeLeafletBuilderEvent;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\Javascript\Output;
|
||||
use Netzmacht\LeafletPHP\Assets;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\Icon;
|
||||
use Netzmacht\LeafletPHP\Leaflet;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
@@ -97,15 +96,13 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
|
||||
foreach ($GLOBALS['LEAFLET_ASSETS'] as $name => $assets) {
|
||||
if (!empty($assets['css'])) {
|
||||
foreach ($assets['css'] as $javascript) {
|
||||
$builder->registerStylesheet($name, $javascript[0], $javascript[1]);
|
||||
}
|
||||
list ($source, $type) = (array) $assets['css'];
|
||||
$builder->registerStylesheet($name, $source, $type ?: Assets::TYPE_FILE);
|
||||
}
|
||||
|
||||
if (!empty($assets['javascript'])) {
|
||||
foreach ($assets['javascript'] as $javascript) {
|
||||
$builder->registerJavascript($name, $javascript[0], $javascript[1]);
|
||||
}
|
||||
list ($source, $type) = (array) $assets['javascript'];
|
||||
$builder->registerJavascript($name, $source, $type ?: Assets::TYPE_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,7 +114,10 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
*/
|
||||
public function loadAssets()
|
||||
{
|
||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/contao/contao-leaflet.js|static';
|
||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/contao/contao-leaflet.js' . (\Config::get('debugMode')
|
||||
? ''
|
||||
: '|static'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,10 +135,6 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
$buffer = '';
|
||||
$icons = array();
|
||||
|
||||
/** @var Leaflet $builder */
|
||||
$builder = $GLOBALS['container']['leaflet.definition.builder'];
|
||||
$encoder = $builder->getBuilder()->getEncoder();
|
||||
|
||||
foreach ($collection as $model) {
|
||||
/** @var Icon $icon */
|
||||
$icon = $mapper->handle($model);
|
||||
@@ -150,7 +146,7 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
if ($icons) {
|
||||
$buffer = sprintf('ContaoLeaflet.loadIcons(%s);', $encoder->encodeValue($icons));
|
||||
$buffer = sprintf('ContaoLeaflet.loadIcons(%s);', json_encode($icons));
|
||||
}
|
||||
|
||||
$file = new \File('assets/leaflet/js/icons.js');
|
||||
@@ -158,7 +154,10 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
$file->close();
|
||||
|
||||
// TODO: Cache it.
|
||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/js/icons.js|static';
|
||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/js/icons.js' . (\Config::get('debugMode')
|
||||
? ''
|
||||
: '|static'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user