Skip to content

Instantly share code, notes, and snippets.

@Megafry
Megafry / setClassRand.js
Created October 20, 2020 09:50
Adds the given class to 1 element from the selection and return it:
// extend jQuery:
$.fn.setClassRand = function(cssClass) {
return this.eq( Math.floor( Math.random() * this.length ) ).addClass(cssClass);
};
//usage:
//add the class "teaser__video--active" and play it:
var video = $(".teaser__video").setClassRand("teaser__video--active");
if (video.length) {
video[0].play();
@Megafry
Megafry / G201.typoscript
Last active November 17, 2021 14:16
TYPO3: add warning text to all external links with regex
page.10.stdWrap.replacement {
10 {
search = #(<a.*?target="_blank".*?>)(.*?)(</a>)#i
replace {
wrap2 = ${1}${2} |${3}
noTrimWrap = |<span class="show-for-sr"> |</span>|
data = LLL:EXT:...locallang.xlf:link_open_in_new_windows
}
useRegExp = 1
}
@Megafry
Megafry / gist:8da833eb5ebd1e0b3be3dfa1554043af
Created October 26, 2021 13:47
Regex xml to xlf (TYPO3)
## Default (locallang.xml to locallang.xlf)
## search
<label index="(.*?)">(.*?)</label>
## replace
<trans-unit id="$1">\n\t<source>$2</source>\n</trans-unit>
## langauge (locallang.xml to de.locallang.xlf)
## search
<label index="(.*?)">(.*?)</label>
## replace
@Megafry
Megafry / FormController.php
Created March 6, 2024 11:48
Formie import/export for console
<?php
namespace modules\ExtendFormie\console\controllers;
use Throwable;
use verbb\formie\helpers\ImportExportHelper;
use yii\console\Controller;
use yii\console\ExitCode;
use yii\helpers\Console;