Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
matthewmorrone / jquery.visible.js
Created December 6, 2014 23:46
:visible pseudoclass for jquery
$.expr[":"].visible = function (a) {
return !(jQuery(a).is(':hidden') || jQuery(a).parents(':hidden').length);
};
@matthewmorrone
matthewmorrone / jquery.caseInsenitive.js
Last active May 1, 2017 20:04
make the :contains pseudoselector case-insensitive
$.expr[":"].contains = $.expr.createPseudo(function (arg) {
return function (elem) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
$.fn.outerHTML = function () {
return $('<div>').append($(this).clone()).html();
}
@matthewmorrone
matthewmorrone / jquery.tag.js
Created December 6, 2014 23:49
acts like a getter/setter for an element's tag
$.fn.tag = function (i) {
if (arguments.length === 0) {
return $(this)[0].tagName;
}
var $this = $(this);
var newnode = $('<' + i + '></' + i '>').html($this.html());
var attributes = $.map(this.attributes, function (item) {
return item.name
})
@matthewmorrone
matthewmorrone / jquery.title.js
Created December 6, 2014 23:50
acts like a getter/setter/ for document title
$.title = function (input) {
if (arguments.length == 0) {
return $("title").html();
}
$("title").html(input);
return this;
}
@matthewmorrone
matthewmorrone / jquery.id.js
Created December 6, 2014 23:51
acts like a getter/setter for id
$.fn.id = function (i) {
if (i === undefined) {
return $(this)[0].id;
}
if (arguments.length == 0) {
return $(this).attr("id");
}
if (i === "") {
$(this).removeAttr("id");
return this;
@matthewmorrone
matthewmorrone / jquery.shuffle.js
Created December 6, 2014 23:53
recursively shuffle descendants of an element
$.fn.shuffle = function () {
return this.each(function () {
var items = $(this).children();
return (items.length) ? $(this).html($.shuffle(items)) : this;
})
}
@matthewmorrone
matthewmorrone / array.filter.js
Created December 6, 2014 23:56
modifies the native map and filter functions to return truthy values in an array if callback is specified
if (Array.prototype.nativeFilter) {
Array.prototype.filter = Array.prototype.nativeFilter;
delete Array.prototype.nativeFilter
}
Array.prototype.define("nativeFilter", Array.prototype.filter);
Array.prototype.filter = function() {
if (arguments.length === 0) {
@matthewmorrone
matthewmorrone / arguments.define.js
Last active August 29, 2015 14:10
Never write "Array.prototype.slice.call(arguments);" ever again! (updated to also augment NodeList)
(function () {
var i, len, methods = Object.getOwnPropertyNames(Array.prototype);
for (i = 0, len = methods.length; i < len; i += 1) {
if (arguments.constructor.prototype.hasOwnProperty(methods[i]) === false) {
arguments.constructor.prototype.define(methods[i], Array.prototype[methods[i]]);
}
if (NodeList.prototype.hasOwnProperty(methods[i]) === false) {
NodeList.prototype.define(methods[i], Array.prototype[methods[i]]);
}
}
@matthewmorrone
matthewmorrone / jquery.disableSelection.js
Created December 7, 2014 14:30
All of my friends are deprecated =[
(function($) {
var selectionDisabled = {
"-webkit-touch-callout": "none",
"-webkit-user-select": "none",
"-khtml-user-select": "none",
"-moz-user-select": "none",
"-ms-user-select": "none",
"user-select": "none"
};