This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var formData = new FormData(); | |
var fileField = document.querySelector("input[type='file']"); | |
formData.append('username', 'abc123'); | |
formData.append('avatar', fileField.files[0]); | |
fetch('https://example.com/profile/avatar', { | |
method: 'PUT', | |
body: formData | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mixin pagination(totalNewsCount, limit, currentPage, num) | |
- let index = 0; | |
- let pageRange = num || 2; | |
- let totalPages = totalNewsCount / limit; | |
- let rangeStart = () => (currentPage - pageRange > 1) ? currentPage - pageRange : 1; | |
- let rangeEnd = () => (currentPage + pageRange < totalPages) ? currentPage + pageRange : totalPages; | |
- let hasFirst = rangeStart !== 1; | |
- let hasLast = rangeEnd() < totalPages; | |
-console.log(!hasFirst) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class OnTop { | |
constructor(element, {speed = 10} = {}) { | |
this.marginY = 0; | |
this.speed = speed; | |
this.scroller = null; | |
this.button = document.querySelector(element); | |
this.button.addEventListener('click', this.toTop.bind(this)); | |
window.onscroll = () => this.marginY = window.pageYOffset; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Slider { | |
constructor({ container, touch = true, autoplay = false, autoplayDelay = 3000}) { | |
this.slider = document.querySelector(container); | |
this.slidesContainer = this.slider.querySelector('.js-carousel__wrap'); | |
this.prevButton = this.slider.querySelector('.js-carousel__prev'); | |
this.nextButton = this.slider.querySelector('.js-carousel__next'); | |
this.currentSlide = 0; | |
this.lastSlide = this.slider.querySelector('.js-carousel__wrap').children.length; | |
this.isAnimationEnd = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extends": [ | |
"airbnb", | |
"prettier", | |
"prettier/react" | |
], | |
"parser": "babel-eslint", | |
"parserOptions": { | |
"ecmaVersion": 8, | |
"ecmaFeatures": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toMatrix(arr, rowSize) { | |
var store = []; | |
for (var i = 0; i < arr.length; i += rowSize) { | |
store.push(data.slice(i, i + rowSize)); /*?*/ | |
} | |
return store; | |
} | |
toMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9], 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function requestAllWithDelay (urls, delay) { | |
return urls.reduce((promise, url) => { | |
return promise | |
.then((responses) => { | |
return fetch(url) // Or whatever request library you're using. If it doesn't support promises, you can wrap it in `new Promise((resolve, reject) => someLib(url, { onSuccess: resolve, onError: reject }));` or something similar. | |
.then(response => { | |
return new Promise(resolve => { | |
setTimeout(resolve, delay, responses.concat(response)); // replies.concat might not work, depending on how you want to accumulate all the data. Maybe you don't even care about the responses? | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const providerContent = await content.reduce((promises, item) => { | |
const { html, type, url } = item; | |
return promises.then(responses => { | |
if (type === 'inlineText') { | |
return new Promise(resolve => resolve(responses.concat([item]))); | |
} | |
return providerService.getProviderResponse({ url, provider: type }) | |
.then(response => { | |
return new Promise(resolve => { | |
console.log({url}) |
OlderNewer