Skip to content

Instantly share code, notes, and snippets.

View jsguy's full-sized avatar

Mikkel Bergmann jsguy

View GitHub Profile
function htmlDecode(input){
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes[0].nodeValue;
}
function HtmlEncode(s)
{
var el = document.createElement("div");
el.innerText = el.textContent = s;
@jsguy
jsguy / withES6.js
Created July 21, 2017 01:45
The with statement in ES6
// Like the with statement, but in ES6 and scoped only onto obj
const withES6 = function(obj, code){
const scope = new Function(...Object.keys(obj), code);
scope(...Object.values(obj));
};
// Test
let myObj = {
res: {},
a: 3,
@jsguy
jsguy / mobilekeyboardfix.jquery.js
Created July 20, 2015 02:01
Allow click to work even when keyboard is shown on mobile device
/*
Make the submit button "click" even when the keyboard is shown
http://stackoverflow.com/questions/24306818/form-submit-button-event-is-not-captured-when-keyboard-is-up-ios-7
http://stackoverflow.com/questions/12690620/checking-if-touchend-comes-after-a-drag
Note: requires jQuery
*/
$(function(){
// Check if the user is dragging
@jsguy
jsguy / mithril.ie.polyfill.js
Last active June 11, 2021 05:06
Mithril IE8 polyfill
// IE polyfills needed by mithril for IE8 and below
// array.indexOf - https://gist.github.com/revolunet/1908355
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0)
@jsguy
jsguy / designer.html
Created September 4, 2014 03:47
designer
<link rel="import" href="../chart-js/chart-js.html">
<link rel="import" href="../ace-element/ace-element.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@jsguy
jsguy / gist:9732087
Created March 24, 2014 00:26
SMH fix
javascript:void((function(){$('#subscription-overlay').remove();$('body').css({overflow: 'auto'}); localStorage.clear(); var a,b,c,e,f;f=0;a=document.cookie.split("; ");for(e=0;e<a.length&&a[e];e++){f++;for(b="."+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,"")){for(c=location.pathname;c;c=c.replace(/.$/,"")){document.cookie=(a[e]+"; domain="+b+"; path="+c+"; expires="+new Date((new Date()).getTime()-1e11).toGMTString());}}};document.location.reload()})())
@jsguy
jsguy / gist:6822077
Created October 4, 2013 07:09
jQuery konamify plugin... why not, it's friday.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<p>
@jsguy
jsguy / gist:6446407
Created September 5, 2013 05:36
Find inputs for cross-browser ajax form submit (works in IE7 even!)
.find('input:not(:disabled)')
<!doctype html>
<!--[if lt IE 9]><html class="ie"><![endif]-->
<!--[if gte IE 9]><!--><html><!--<![endif]-->
<!--
The comment jumble above is handy for targeting old IE with CSS.
http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
-->
<head>
@jsguy
jsguy / gist:6067483
Created July 24, 2013 01:29
When using jQuery, and you need to select elements with weird IDs, this is handy
// Escape unwanted CSS selector chars
escapeForJquery = function(str) {
var charList = ["\\", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", "-", ",", ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "]", "^", "`", "{", "|", "}", "~"],
i, result = str;
for(i = 0; i < charList.length; i+=1) {
result = result.split(charList[i]).join("\\" + charList[i]);
}
return result;
};