Skip to content

Instantly share code, notes, and snippets.

View rblakejohnson's full-sized avatar

Blake Johnson rblakejohnson

View GitHub Profile

Keybase proof

I hereby claim:

  • I am rblakejohnson on github.
  • I am beedewok (https://keybase.io/beedewok) on keybase.
  • I have a public key ASDIFdqVU3kvAV17EJHHYaeFew7tkOeQTx1rPMkacfVYRAo

To claim this, I am signing this object:

function fakeRequest(delay=1000, result='success') {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (result === 'success') {
resolve();
}
if (result === 'error') {
reject();
}
if (result === 'random') {
@rblakejohnson
rblakejohnson / setEndOfContenteditable
Created January 10, 2018 21:45
Set cursor to the end of Contenteditable
function setEndOfContenteditable(contentEditableElement) {
var range = document.createRange();//Create a range (a range is a like the selection but invisible)
var selection = window.getSelection();//get the selection object (allows you to change selection)
range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection.removeAllRanges();//remove any selections already made
selection.addRange(range);//make the range you have just created the visible selection
}
// found here https://stackoverflow.com/posts/3866442/revisions
[
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" },
{ "keys": ["ctrl+s"], "command": "toggle_side_bar" },
{ "keys": ["super+shift+r"], "command": "reindent" }
]
@rblakejohnson
rblakejohnson / new_gist_file.js
Created December 11, 2013 18:36
delay action on keypress to improve performance
var i = 0;
$('input').keypress(function() {
if (this.timeoutId) {
window.clearTimeout(this.timeoutId);
}
this.timeoutId = window.setTimeout(function () {
// do something
}, 200);
});
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modal Sans-JS</title>
<style>
* { box-sizing: border-box }
body {
@rblakejohnson
rblakejohnson / new_gist_file.js
Created September 23, 2013 22:20
JS: browser detect
(function(){
var putHere = $("html"),
curBrowser;
if($.browser.msie){
curBrowser = "ie";
putHere.addClass("ie"+parseInt($.browser.version,10));
}
if($.browser.webkit){
curBrowser = "webkit";
@rblakejohnson
rblakejohnson / new_gist_file.js
Created September 23, 2013 16:01
JS: FAQ toggle and close
$('.question').on('click', function(e) {
e.preventDefault();
var self = $(this);
self.toggleClass("active").next().slideToggle(350);
});
$('.answer .close').on('click', function(e) {
e.preventDefault();
var answer = $(this).parents(".answer");
answer.slideUp(350);
@rblakejohnson
rblakejohnson / new_gist_file
Created September 11, 2013 15:19
JS: animated scroll
$('a').on('click', function() {
$('html,body').animate({
scrollTop: $('.box').offset().top - 10
}, 200);
});
@rblakejohnson
rblakejohnson / new_gist_file
Created September 4, 2013 21:06
HTML: Kitchen sink
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">