contao-components/mootools
Customized MooTools JavaScript distribution packaged for integration with the Contao Open Source CMS, providing the framework bundle Contao expects for legacy components and extensions.
Installation Require the package via Composer:
composer require contao-components/mootools
Publish the assets (if using Contao integration):
php artisan vendor:publish --tag=mootools-assets
First Integration Include MooTools in a Blade template:
@mootools
This injects the MooTools script into your layout (typically in the footer).
Basic Usage Example Add a click handler to a button:
document.addEvent('domready', function() {
$('myButton').addEvent('click', function() {
alert('Button clicked!');
});
});
Ensure your HTML includes:
<button id="myButton">Click Me</button>
Where to Look First
vendor/contao-components/mootools/src/ for core files.public/vendor/mootools/ (if published).resources/views/vendor/mootools.blade.php for template logic.Legacy Contao Migration
Fx and Class utilities.// Contao-style modal in Laravel
var modal = new Element('div', {
'class': 'modal',
styles: {
display: 'none'
}
}).inject(document.body);
modal.addEvent('click:relay(.close)', function() {
modal.setStyle('display', 'none');
});
Isolated MooTools Components
// app/Http/Middleware/MooToolsMiddleware.php
public function handle($request, Closure $next) {
if ($request->is('admin/*')) {
$request->mootools = true;
}
return $next($request);
}
@if(request()->mootools)
@mootools
@endif
Laravel + MooTools AJAX
Request for API calls to Laravel endpoints.new Request({
url: '/api/update-status',
method: 'post',
data: { status: 'active' },
onSuccess: function(response) {
$('statusIndicator').set('text', response.status);
}
}).send();
Dynamic Asset Loading
<script>
document.addEvent('domready', function() {
var script = new Element('script', {
src: "{{ asset('vendor/mootools/mootools-core.js') }}",
type: 'text/javascript'
}).inject(document.head);
});
</script>
Integration with Laravel Mix
// webpack.mix.js
mix.js('resources/js/mootools-app.js', 'public/js')
.alias({
mootools: path.resolve(__dirname, 'node_modules/mootools/mootools-core.js')
});
// resources/js/mootools-app.js
import 'mootools';
document.addEvent('domready', () => {
console.log('MooTools ready!');
});
DOM Ready Race Conditions
domready.document.addEvent('domready', function() {
// Your MooTools code
});
Selector Conflicts
$$() and $() selectors may conflict with jQuery or vanilla JS.Laravel Mix Bundling Issues
import 'mootools';
// Your app code
Contao-Specific Quirks
Contao.Fx) may not work out-of-the-box.Performance Overhead
Deprecation Warnings
Console Errors
try-catch blocks to handle MooTools errors gracefully:
try {
$$('.nonexistent').addEvent('click', function() {});
} catch (e) {
console.error('MooTools error:', e);
}
Selector Debugging
console.log($$('body .my-class').length); // Check if elements are found
Event Listener Leaks
var event = $('element').addEvent('click', function() {});
// Later...
event.remove();
Laravel Logs
tail -f storage/logs/laravel.log
Custom MooTools Builds
Core, Element, Request) to reduce bundle size.Laravel Facades
// app/Facades/MooTools.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class MooTools extends Facade {
protected static function getFacadeAccessor() { return 'mootools'; }
}
// app/Providers/MooToolsServiceProvider.php
public function register() {
$this->app->singleton('mootools', function() {
return new \MooTools\MooTools();
});
}
Blade Directives
// app/Providers/BladeServiceProvider.php
Blade::directive('mootools', function() {
return '<script src="{{ asset("vendor/mootools/mootools-core.js") }}"></script>';
});
Testing
$this->withoutJavaScript(); // Disable JS if not needed
// Or mock MooTools in PHPUnit:
$this->partialMock(MooTools\MooTools::class, ['someMethod']);
How can I help you explore Laravel packages today?