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 es = new EventSource('/console'); | |
es.onmessage = function (event) { | |
var data = JSON.parse(event.data); | |
execute(data.command); | |
}; | |
//custom message type | |
es.addEventListener('reload', function() { | |
reloadData(); |
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() | |
for (var i = 0; i < files.length; i++){ | |
formData.append('file', files[i]); | |
} | |
//new post a new XHR request | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', url); | |
xhr.upload.onprogress = function (event){ | |
if (event.lengthComputable) { |
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 readFiles(files){ | |
for (var i = 0; i < files.length; i++){ | |
preview(files[i]); | |
} | |
} | |
function preview(file){ | |
var reader = new FileReader(); | |
reader.onload = function (event) { | |
var image = new Image(); |
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 prettyDate(time){ | |
var date = new Date(time || ""), | |
diff = ((new Date().getTime() - date.getTime()) / 1000), | |
day_diff = Math.floor(diff / 86400); | |
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) { | |
return; | |
} | |
return day_diff == 0 && ( |
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 i = 0; | |
var numTouches = 0; | |
function touch( ev ) { | |
i++; | |
var out = document.getElementById('out'); | |
if( ev.type == 'touchstart' ) { | |
out.value += i + ': touch start\n'; | |
numTouches++; | |
} |
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 randomString(string_length) | |
{ | |
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; | |
var output = ""; | |
var index; | |
for (var i = 0; i < string_length; i++) | |
{ | |
var index = Math.floor(Math.random() * chars.length); | |
output += chars.substring(index, index + 1); |
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
jQuery.fn.center = function() { | |
_TOP = (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop(); | |
_TOP = (_TOP <= 0) ? 0 : _TOP; | |
_LEFT= (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft(); | |
_LEFT = (_LEFT <= 0) ? 0 : _LEFT; | |
this.css({ | |
top:_TOP + "px", | |
left:_LEFT + "px" | |
}); | |
return this; |
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
//Conditionally load jQuery | |
//inspired by http://www.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/ | |
window.onload = function () { | |
if (typeof jQuery == 'undefined') { | |
var jQ = document.createElement('script'); | |
jQ.type = 'text/javascript'; | |
jQ.onload = jQ.onreadystatechange = myOnLoadEvent; | |
jQ.src = ( "https:" == location.protocol ? "https//" : "http//" ) + 'ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'; | |
document.body.appendChild(jQ); |
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
<datalist id="statelist"> | |
<option value="Alabama"></option> | |
<option value="Alaska"></option> | |
<option value="Arizona"></option> | |
<option value="Arkansas"></option> | |
<option value="California"></option> | |
<option value="Colorado"></option> | |
<option value="Connecticut"></option> | |
<option value="Delaware"></option> | |
<option value="District of Columbia"></option> |
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
$(document).ready(function() { | |
if ( !("placeholder" in document.createElement("input")) ) { | |
$("input[placeholder]").each(function() { | |
var val = $(this).attr("placeholder"); | |
if ( this.value == "" ) { | |
this.value = val; | |
} | |
$(this).focus(function() { | |
if ( this.value == val ) { |