Skip to content

Instantly share code, notes, and snippets.

View Bewitchedyegor's full-sized avatar

Yegor Ostapenko Bewitchedyegor

View GitHub Profile
@Bewitchedyegor
Bewitchedyegor / daterangepicker_pick.js
Created October 12, 2017 14:01
Add action on daterangepicker pick
$('#pick_period').on('apply.daterangepicker', (ev, picker) => {
//insert your action here
});
@Bewitchedyegor
Bewitchedyegor / daterangepicker_ru.js
Created October 12, 2017 13:43
Localize Bootstrap daterangepicker to Russian
$('input[id="pick_period2"]').daterangepicker({
singleDatePicker: true,
showDropdowns: false,
minDate: moment(today).add(1, 'days'),
maxDate: moment(today).add(45, 'days'),
//add locale to your daterangepicker call function
locale: {
format: 'DD-MM-YYYY',
applyLabel: 'Принять',
cancelLabel: 'Отмена',
@Bewitchedyegor
Bewitchedyegor / reset_value.js
Created October 12, 2017 13:35
Change number inside input if maximum/minimum value is reached
$('#pickAgeStart').on('keyup keydown click change', function(e) {
if ($(this).val() > 65 && e.keyCode !== 46 && e.keyCode !== 8) { //insert your value and < or >
e.preventDefault();
$(this).val(65); //insert maximum/minimum value here
}
});
@Bewitchedyegor
Bewitchedyegor / close_container.js
Created October 12, 2017 13:13
Closing any container when clicking outside of it
$(document).mouseup(function(e) {
let container = $(".js-postOptionsMenu"); //insert container selector, multiple selectors for different containers will work fine
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.fadeOut();//you can replace .fadeOut() with any other way to hide your container
}
});
@Bewitchedyegor
Bewitchedyegor / copy_url.js
Last active October 12, 2017 12:59
Copy direct link to post in newsfeed into clipboard on click
$('.copyLink').click( function(e) {
let currenturl = 'http://'; //your domain
let userid = $('html').find('.profileImage a').attr('href'); //get user ID
let postid = $(e.target).parent().attr('id'); //get post ID
let urlcopy = currenturl + userid + '#' + postid; //get the full link
let $temp = $("<input>"); //create fake input
$("body").append($temp); //add fake input to HTML
$temp.val(urlcopy).select(); //insert full link to fake input
document.execCommand("copy"); //copy full link from fake input to clipboard
$temp.remove(); //remove fake input from HTML