Created
October 26, 2011 18:24
-
-
Save buzzedword/1317261 to your computer and use it in GitHub Desktop.
Useful plugins found in my travels...
This file contains 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
// Array Remove - By John Resig (MIT Licensed) | |
Array.prototype.remove = function(from, to) { | |
var rest = this.slice((to || from) + 1 || this.length); | |
this.length = from < 0 ? this.length + from : from; | |
return this.push.apply(this, rest); | |
}; | |
// usage: log('inside coolFunc', this, arguments); | |
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ | |
window.log = function(){ | |
log.history = log.history || []; // store logs to an array for reference | |
log.history.push(arguments); | |
if(this.console) { | |
arguments.callee = arguments.callee.caller; | |
var newarr = [].slice.call(arguments); | |
(typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr)); | |
} | |
}; | |
// make it safe to use console.log always | |
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try | |
{console.log();return window.console;}catch(err){return window.console={};}})()); | |
/* | |
* $.inJSON utility | |
* | |
* Searches arbitrary JSON for a key and returns an array of all matches. | |
* Intended for use with jQuery 1.4.2 | |
* | |
* Copyright (c) 2010 Dan Connor | |
* www.danconnor.com | |
* | |
* Dual-licensed under the MIT and GPL licenses: | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.gnu.org/licenses/gpl.html | |
*/ | |
(function($, undefined){ | |
$.extend($, { | |
inJSON: function(json, key){ | |
var hit, hits = []; | |
$.each(json, function(k,v){ | |
if (k === key) | |
hits.push(v); | |
if (typeof(v) === "string"){ | |
return true; | |
} else if ($.isArray(v) || $.isPlainObject(v)) { | |
var r = $.inJSON(v, key); | |
if (r.length > 0) | |
hits = hits.concat(r); | |
} | |
}); | |
return hits; | |
} | |
}); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment