Hi guys!
I'm trying to replace an especific string (i.imgur.com) to another string (imgur.com) while typing on flarum. I tested with a normal document and worked but on flarum it doesnt.
i tried to extend, but i guess i did something wrong:
use Flarum\Extend;
use Flarum\Frontend\Document;
return [
(new Extend\Frontend('forum'))
->content(function (Document $document) {
$document->head[] = '
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(function() {
$('*[id^="textarea"]').keyup(function() {
$(this).val($(this).val().replace("i.imgur.com", "imgur.com"));
});
});
</script>
';
})
];
it returns an error because of this -> }); here and the id, but ok.
i put so this into a script.js file and linke with src
use Flarum\Extend;
use Flarum\Frontend\Document;
return [
(new Extend\Frontend('forum'))
->content(function (Document $document) {
$document->head[] = '
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://myforum.com/script.js"></script>
';
})
];
but the code still dont work, the forum loads but nothing happens when i type the link.
what i want is that jquery read what is writen on composer texteditor and return other string on keyup, replace it in case. my code works in a textarea that i did myself, but on flarum simply doesn't, my extend is wrong? what i'm doing wrong? i read the documentation but dont know how to extend javascript to text formatter 🙁