Skip to content

Instantly share code, notes, and snippets.

View w-jerome's full-sized avatar
💻
coding…

Jérôme Wohlschlegel w-jerome

💻
coding…
View GitHub Profile
@w-jerome
w-jerome / convert-values-type.php
Last active April 13, 2018 12:41
PHP — Convert Values Type
function convertValueType ( $value ) {
$valueConvert = intval($value);
if ($value === "0") {
$value = intval($value);
} else if ($value === true || $value === "true") {
$value = true;
} else if ($value === false || $value === "false") {
$value = false;
} else if ($value === null || $value === "null") {
@w-jerome
w-jerome / replace-string-with-array.php
Last active April 13, 2018 12:41
PHP — Replace string with array
<?php
$html = "My name is {name}, {forname} !";
$replaceBy = array(
"{name}" => "John",
"{forname}" => "Doe",
);
$html = str_replace(array_keys($replaceBy), array_values($replaceBy), $html);
var_dump($html);
@w-jerome
w-jerome / url-lang-redirection.php
Last active April 13, 2018 12:42
PHP — Url lang redirection
<?php
// On check d'abord si on a déjà était "routé" par le système de langue en "fr" ou "en" (ou les langues disponible)
$url = trim($_SERVER['REQUEST_URI'], "/");
// On définis les langues possibles
$langList = ["fr", "en"];
// On prépare le regex qui va vérifier si l'url contient le "routage" par la langue
$langRegex = "";
$langRegex1 = array_map(function($value) { return "$value$"; }, $langList);
$langRegex2 = array_map(function($value) { return "$value\/"; }, $langList);
@w-jerome
w-jerome / accordion.html
Last active March 27, 2019 08:42
Javascript and jQuery — Accordion
<!-- https://codepen.io/w-jerome/pen/ggyedz -->
<ul class="accordion__list">
<li class="accordion__item">
<div class="accordion__header">
<span class="accordion__title">
Item
</span>
<button type="button" class="accordion__btn" style="margin-left:20px;">▾</button>
</div>
@w-jerome
w-jerome / fullscreen-support.js
Last active March 27, 2019 08:42
Javascript — Check if browser support fullscreen
function canGoFullscreen() {
var el = document.body;
var check = typeof el.requestFullscreen !== 'undefined' ||
typeof el.mozRequestFullScreen !== 'undefined' ||
typeof el.webkitRequestFullscreen !== 'undefined' ||
typeof el.msRequestFullscreen !== 'undefined' ||
typeof document.exitFullscreen !== 'undefined' ||
typeof document.mozCancelFullScreen !== 'undefined' ||
typeof document.webkitExitFullscreen !== 'undefined';
@w-jerome
w-jerome / scrollTo.js
Last active March 27, 2019 08:42
Javascript — Scroll To
// vanillaJS : window.scrollTo(0,0)
var $links = document.querySelectorAll('a[href*="#"]');
for (var i = 0; i < $links.length; i++) {
$links[i].onclick = function() {
var selector = this.href.split('#')[1];
var $target = document.querySelector('#'+selector);
@w-jerome
w-jerome / js-quick-helpers.js
Last active August 31, 2022 00:26
Javascript — Quick Helpers
function addClass (el, className) {
if (typeof el !== 'object' || typeof className !== 'string') { return }
if (el.classList) {
el.classList.add(className);
} else {
el.className += ' ' + className;
}
}
@w-jerome
w-jerome / scrollPosition.js
Last active March 27, 2019 08:42
Javascript — Scroll Position
var $section = document.querySelectorAll('.section'),
currentSectionID = '',
scroll;
window.onscroll = function() {
scroll = document.body.scrollTop;
for (var i = 0; i < $section.length; i++) {
if (currentSectionID !== $section[i].id) {
@w-jerome
w-jerome / input-number-arrows.html
Last active February 8, 2025 00:40
HTML — Input number custom arrows
<!--
https://stackoverflow.com/questions/45396280/customizing-increment-arrows-on-input-of-type-number-using-css
https://www.w3schools.com/jsref/met_number_stepup.asp
-->
<link media="all" rel="stylesheet" href="./style.css">
<div>
<button type="button" onclick="this.parentNode.querySelector('[type=number]').stepDown();">
-
@w-jerome
w-jerome / detect-browser.js
Last active March 27, 2019 08:41
Javascript and PHP — Detect Browser
var browser = (navigator.userAgent.indexOf("Chrome") > -1) ? 'chrome' : (navigator.userAgent.indexOf("Safari") > -1) ? 'safari' : (navigator.userAgent.indexOf("Opera") > -1) ? 'opera' : (navigator.userAgent.indexOf("Firefox") > -1) ? 'firefox' : (navigator.userAgent.indexOf("MSIE") > -1 || navigator.userAgent.indexOf("Trident") > -1) ? 'ie' : 'unknow';