Skip to content

Instantly share code, notes, and snippets.

@sibicode
sibicode / axios-catch-error.js
Created November 28, 2018 11:33 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
axios.put(this.apiBaseEndpoint + '/' + id, input)
.then((response) => {
// Success
})
.catch((error) => {
// Error
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
// console.log(error.response.data);
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<header id="header" class="header">
@sibicode
sibicode / vanilla-js-project-ideas.md
Created September 26, 2018 14:15
A few project ideas to help you learn vanilla JavaScript. https://gomakethings.com
  1. Toggle Tab.s Clicking a link opens a tab and closes all the others. You should ideally be able to have multiple tab sections on a page working independently of each other.
  2. Modals. Clicking a link opens up a modal dialogue window.
  3. Save Form Data. When someone updates a form field (or clicks a "Save" button, your choice), save their form data to localStorage. If they refresh the page, reload their saved data into the field.
  4. Toggle Password Visibility. Checking a checkbox reveals the password in an input[type="password"] field in plain text so users can verify that they typed it correctly.
  5. Make Content the Same Height. If you have a few columns of text, side-by-side but different heights (with a background color or something), set them all to be as tall as the tallest content area.
  6. Generate a Table of Contents. Automatically generate a table of contents based on the h2-h6 headings on the page.
@sibicode
sibicode / percentages.js
Created September 26, 2018 14:14
Figuring out how much of the page you've scrolled or whatever
//
// Methods
//
/**
* Get an element's distance from the top of the page
* @param {Node} elem The element
* @return {Number} Distance from the top of the page
*/
var getElemDistance = function ( elem ) {
@sibicode
sibicode / es7-async-await.js
Created September 15, 2018 17:29
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@sibicode
sibicode / sticky-footer.css
Created August 29, 2018 08:20
Flexbox sticky footer (IE 11)
@sibicode
sibicode / swiper-magnific-popup.js
Created November 17, 2017 12:02 — forked from thiagoeliasr/swiper-magnific-popup.js
Adding swipe support to Magnific Popup galleries. (touchSwipe is required: http://labs.rampinteractive.co.uk/touchSwipe/demos/)
(function() {
/* Define a variável que dá swipe no lightbox */
var magnificPopup = $.magnificPopup.instance;
/* Carrega a função quando clica no lightbox (senão não pega a classe utilizada) */
$("a.image-lightbox").click(function(e) {
/* Espera carregar o lightbox */
setTimeout(function() {
/* Swipe para a esquerda - Próximo */
@sibicode
sibicode / script.js
Created July 25, 2017 16:01
slick slider only mobile
$slick_slider = $('.slider');
settings = {
slidesToShow: 2,
slidesToScroll: 2,
infinite: false,
arrows: false
}
$slick_slider.slick(settings);
@sibicode
sibicode / script.js
Created July 17, 2017 04:07
Smooth scroll to element
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 56
}, 500);
return false;
}
@sibicode
sibicode / form.js
Created June 8, 2017 10:46
Проверка на заполнение полей формы
$('.callback-form').each(function(){
// Объявляем переменные (форма и кнопка отправки)
var form = $(this),
btn = form.find('.callback-form__submit');
// Добавляем каждому проверяемому полю, указание что поле пустое
form.find('.callback-form__input').addClass('empty');
// Функция проверки полей формы
function checkInput(){