Installation Add the package via Composer:
composer require atm/emojisbundle
Publish the assets (if needed):
php artisan vendor:publish --provider="Atm\EmojisBundle\EmojisBundleServiceProvider" --tag=public
Basic Usage
Include the JS/CSS in your layout (check resources/views/layouts/app.blade.php or similar):
<link href="{{ asset('vendor/emojis/css/emojis.css') }}" rel="stylesheet">
<script src="{{ asset('vendor/emojis/js/jquery.emojis.js') }}"></script>
First Use Case
Convert a <textarea> into an emoji picker:
<textarea id="comment" name="comment"></textarea>
Initialize with jQuery:
$(document).ready(function() {
$('#comment').emojis();
});
Dynamic Initialization Use event delegation for AJAX-loaded forms:
$(document).on('emojis:init', 'textarea.emoji-enabled', function() {
$(this).emojis();
});
Customizing Emoji Sets Override the default emoji set via config (publish config first):
// config/emojis.php
'emoji_set' => 'custom-set',
Then include your custom set in the JS:
$.emojis.options.emoji_set = 'custom-set';
Integration with Laravel Forms Use Blade directives for consistency:
// In a Blade component
<textarea class="form-control emoji-enabled" name="content"></textarea>
Initialize in a global JS file:
$(function() {
$('.emoji-enabled').emojis();
});
Server-Side Handling Sanitize emojis in Laravel validation rules:
$request->validate([
'content' => 'required|string|emoji_safe', // Custom rule
]);
$('textarea').on('focus', function() {
if (!$(this).data('emojis-inited')) {
$(this).emojis();
$(this).data('emojis-inited', true);
}
});
.emojis-wrapper and .emojis-picker.jQuery Dependency
jquery.emojis.js.jQuery is not defined errors.Asset Paths
public/vendor/emojis/ or configure your build tool to include them.mix.copy() in webpack.mix.js:
mix.copy('node_modules/atm-emojisbundle/dist', 'public/vendor/emojis');
Emoji Shortcode Conflicts
:smile:) may conflict with Laravel Blade syntax.shortcodes config option to customize or disable them:
'shortcodes' => false,
Caching Issues
$('#dynamic-textarea').html(newContent).emojis();
$.emojis.options.debug = true;
FileNotFoundException if assets aren’t published.Custom Emoji Categories
Extend the default categories by overriding the emoji_categories config array:
'emoji_categories' => [
'custom' => [
'name' => 'Custom',
'emojis' => ['custom1', 'custom2'],
],
],
Event Listeners Hook into emoji selection events:
$('#textarea').emojis({
onSelect: function(emoji) {
console.log('Selected:', emoji);
// Trigger Laravel event via JS
window.Laravel.echo('emoji.selected', { emoji });
}
});
Server-Side Emoji Processing Use Laravel middleware to process emojis before saving:
// app/Http/Middleware/ProcessEmojis.php
public function handle($request, Closure $next) {
if ($request->has('content')) {
$request->merge([
'content' => $this->convertEmojiShortcodes($request->content),
]);
}
return $next($request);
}
How can I help you explore Laravel packages today?