-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.compare.min.js
11 lines (10 loc) · 1.8 KB
/
jquery.compare.min.js
1
2
3
4
5
6
7
8
9
10
11
/**
* jQuery Compare
*
* jQuery Compare is a simple jQuery plugin that helps compare array and object litterals.
*
* version: 0.7.0
* author: Steve Worley <[email protected]>
* url: http://steveworley.me/jquery-compare
*/
+function(a){a.fn.compare=function(e,d,g){var j=true,k=a.isArray(e),o=(k)?this:this[0],n=(k)?a.extend([],e):a.extend({},e),f=a(o),r={};if(typeof d=="object"){a.extend(r,a.fn.compare.defaults,d)}else{a.extend(r,a.fn.compare.defaults)}r.success=(arguments.length==2&&typeof d=="function")?d:(typeof g=="function")?g:r.success;if(r.sort&&k){if(r.caseSensitive){o.sort();n.sort()}else{o.sort(a.fn.compare.caseSort);n.sort(a.fn.compare.caseSort)}}var m=a.map(o,function(s,b){return b}).length,l=a.map(n,function(s,b){return b}).length;if(m!=l&&!r.fuzzy){j=false}if(k===false){if(r.caseSensitive==false){var c={},q={};a.map(o,function(i,b){c[b.toLowerCase()]=i});a.map(n,function(i,b){q[b.toLowerCase()]=i});o=c;n=q}for(var p in o){if(typeof o[p]!==typeof n[p]){j=false}else{if(typeof o[p]=="function"){j=o[p].toString()==n[p].toString()}else{if(o[p]instanceof Object&&n[p]instanceof Object){j=a(o[p]).compare(n[p])}else{if(r.caseSensitive==false&&typeof o[p]=="string"){j=o[p].toLowerCase()==n[p].toLowerCase()}else{if(o[p]!==n[p]){j=false}}}}}if(!j){break}}}else{for(var h=0;h<o.length;h++){if(typeof o[h]=="string"&&!r.caseSensitive){if(typeof n[h]!="string"||o[h].toLowerCase()!=n[h].toLowerCase()){j=false;break}}else{if(o[h]!=n[h]){j=false;break}}}}if(!j){f.compareError=true;r.error.apply(this,[f]);return f}f.compareError=false;r.success.apply(this,[f]);return f};a.fn.compare.defaults={fuzzy:false,sort:true,caseSensitive:true,success:function(){},error:function(){}};a.fn.compare.caseSort=function(d,c){if(typeof d=="number"){return d-c}return d.toLowerCase().localeCompare(c.toLowerCase())}}(jQuery);