Skip to content

Instantly share code, notes, and snippets.

View JamesMGreene's full-sized avatar

James M. Greene JamesMGreene

View GitHub Profile
@JamesMGreene
JamesMGreene / clipboard.md
Last active August 29, 2015 13:56
HTML5 Clipboard API enhancements
@JamesMGreene
JamesMGreene / interface-for-reporters.js
Last active August 29, 2015 13:57
QUnit's WIP proposal for a standardized reporter interface and data structure among JS testing frameworks. The goal is to be able to reuse existing/new reporters in any of the major JS test frameworks.
var reporterInterface = {
"start": function(data) {
/*
data: {
}
*/
},
@JamesMGreene
JamesMGreene / clickToCopy_queryCommand.js
Last active August 29, 2015 14:01
An example of how synthetic click-to-"copy" events might look if we use `document.execCommand`.
var hasModernClipboardApi, queryCopySupported, syntheticCopySupported, button;
hasModernClipboardApi = window.ClipboardEvent != null;
try {
queryCopySupported = document.queryCommandSupported("click-to-copy") === true;
}
catch (e) {
queryCopySupported = false;
@JamesMGreene
JamesMGreene / README.md
Last active August 29, 2015 14:02 — forked from cphoover/gist:6228063
Polyfill for `document.currentScript`. Demo @ http://jsfiddle.net/JamesMGreene/9DFc9/
@JamesMGreene
JamesMGreene / queryCommand.js
Last active August 29, 2015 14:06
An example of discovering if a queryCommand works in a cross-browser, old-browser compliant way.
function runQueryCommand(command, showUI, value) {
var commandWorked = false,
initialDesignMode = document.designMode || "off";
try {
document.designMode = "on";
commandWorked = !!(
document.queryCommandSupported(command) &&
document.queryCommandEnabled(command) &&
document.queryCommand(command, showUI, value)
@JamesMGreene
JamesMGreene / index.html
Last active August 29, 2015 14:14
Basic `document.readyState`/`script.readyState` tests
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Basic `document.readyState`/`script.readyState` tests</title>
<script id="loadFirst">
function getScriptIds(scriptEls) {
var scriptIds = [];
if (scriptEls) {
for (var i = 0, len = scriptEls.length; i < len; i++) {
@JamesMGreene
JamesMGreene / index.html
Last active August 29, 2015 14:14
Basic `script.readyState`/`document.readyState` tests
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Basic `script.readyState`/`document.readyState` tests</title>
<script id="loadFirst">
window.console && console && console.log && console.log("loadFirst script, evaluating first line");
function _write(msg) {
var bod = document.body || document.getElementsByTagName("body")[0];
<!doctype html>
<html>
<head>
<title>currentScript Example</title>
<script type="text/javascript" id="mainscript" async>
if (document.currentScript && document.currentScript.async) {
console.log("Executing asynchronously");
} else {
@JamesMGreene
JamesMGreene / NoRootNamespaceEnforcement.js
Created July 8, 2012 12:14
Shortcut functions to easily create deep namespaces in JavaScript
(function(exports) {
/**
* @namespace My namespace!
*/
exports.MyNS = {
/**
* Returns the namespace object specified and creates it if it doesn't exist.
* Does NOT enforce that any requested namespace is attached to the MyNS root namespace.
*
* @param {String} nsString A string representation of the desired namespace.
// Response to question on PhantomJS forum: https://groups.google.com/forum/#!topic/phantomjs/DouaSrjwwCE
function doAlpha(url) {
var page = require('webpage').create();
page.open(url, function(status) {
if (status === 'success') {
elements = page.evaluate(function() {
// ...
return result;
});