Skip to content

Instantly share code, notes, and snippets.

View stevoland's full-sized avatar

Stephen Collings stevoland

View GitHub Profile
@stevoland
stevoland / getCSSSelector.js
Created September 13, 2012 11:11
Get CSS Selector for an element
function getCSSSelector(el) {
var names = [];
while (el.parentNode) {
if (el.id) {
names.unshift('#' + el.id);
break;
} else {
if (el == el.ownerDocument.documentElement) {
names.unshift(el.tagName);
} else {
@stevoland
stevoland / jquery.centerInViewport.js
Created September 12, 2012 09:48
jQuery Center in viewport method
/**
* Vertically center an element (popup modal) to the viewport
* If the element is taller than the window height absolute positioning is
* used so that the element will scroll with the docuemnt
*
* @param {boolean} animate Animate to new position or move immediately? Defaults true
* @param {boolean} centerHorizontal Center the element horizontally? Defaults true
* @param {boolean} centerVertical Center the element vertically? Defaults true
*
* @chainable
@stevoland
stevoland / hyphenateLongWords.js
Created September 12, 2012 09:45
Hyphenate long words
/**
* Add a soft hypen (­) to any words in the string longer than the given character length
*
* @param {string} str Input string
* @param {int} maxWordSize Max character length of a word
* @param {int} minFragmentSize [optional] Minimum chars to leave after a hyphen
* @return {string}
*/
var hyphenateLongWords = function (str, maxWordSize, minFragmentSize) {
// TODO: Find out char codes of word break chars