Skip to content

Instantly share code, notes, and snippets.

View nborko's full-sized avatar

Nick Borko nborko

  • San Antonio, TX
View GitHub Profile
@nborko
nborko / jquery.scrollparent.js
Created March 28, 2016 18:52
Like jquery-ui scrollParent function except it works on jQuery objects containing multiple elements
/* like jquery-ui scrollParent function except it works on jQuery objects containing multiple elements */
(function ($) {
$.fn.scrollParent = (function (overflowRegex) {
return function () {
return $($.unique(this.map(function () {
var position = $(this).css('position'),
excludeStaticParent = position === 'absolute',
scrollParent = $(this).parents().filter(function() {
var parent = $(this);
if (excludeStaticParent && parent.css('position') === 'static') {
@nborko
nborko / jquery.focus-shim.js
Created March 28, 2016 18:34
jQuery shim to focus on any element regardless of tabindex
/* jquery shim to focus on any element regardless of tabindex */
(function($) {
$.fn.focus = (function(focus) {
return function () {
if (arguments.length > 0) {
return focus.apply(this, arguments);
}
if (typeof $(this).attr('tabindex') === 'undefined') {
return focus.call(this.attr('tabindex', '-1')).removeAttr('tabindex');
}
@nborko
nborko / jquery.svg-class-shim.js
Last active March 28, 2016 18:38
jquery shims for [add|remove|has]Class for svg
/* jquery shims for [add|remove|has]Class for svg */
(function ($) {
$.fn.addClass = (function(addClass) {
return function(value) {
return addClass.apply(this, arguments).each(function () {
if (this instanceof SVGElement) {
$(this).attr('class', $('<div/>', {'class': $(this).attr('class')}).addClass(value).attr('class'));
}