forked from Idered/cssParentSelector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuery.cssParentSelector.min.js
9 lines (9 loc) · 1.82 KB
/
jQuery.cssParentSelector.min.js
1
2
3
4
5
6
7
8
9
/**
* jQuery cssParentSelector 1.0.9
* https://github.com/Idered/cssParentSelector
*
* Copyright 2011-2012, Kasper Mikiewicz
* Released under the MIT and GPL Licenses.
* Date 2012-02-08
*/
(function(a){a.fn.cssParentSelector=function(){var u=0,m,j,v={checked:"click",focus:"focus blur",active:"mousedown mouseup",selected:"change",changed:"change"},p={mousedown:"mouseout"},q={mouseup:"mouseout"},k={after:"appendTo",before:"prependTo"},b,n,o,d,r,g,s,l,e,h,i,w=/[\w\s\"\'\.\[\]\(\)\=\*\-\:#]*(?=!)[\w\s\.\,\[\]\(\)\=\*\-\:#>!]+[\w\s\"\'\.\,\[\]\=\:\-#>]*\{{1}[\.\*\/\?\:\^\+\\\=\|\w\s\'-;#%]+\}{1}/gi,t=function(f){f=f.replace(/(\/\*([\s\S]*?)\*\/)/gm,"");if(n=f.match(w)){b="";for(m=-1;n[++m],style=n[m];)if(o=style.split("{")[0].split(","),e="{"+style.split(/\{|\}/)[1].replace(/^\s+|\s+$[\t\n\r]*/g,"")+"}","{}"!==e){e=e.replace(/;/g," !important;");for(j=-1;o[++j],d=a.trim(o[j]);)j&&(b+=","),/!/.test(d)?(r=a.trim(d.split("!")[0].split(":")[0]),g=a.trim(d.split("!")[1].split(">")[0].split(":")[0])||[]._,h=a.trim(d.split(">")[0].split("!")[0].split(":")[1])||[]._,i=g?a.trim(d.split(">")[0].split("!")[1].split(":")[1])||[]._:[]._,s=a(a.trim(d.split(">")[1]).split(":")[0]),l=(d.split(">")[1].split(/:+/)[1]||"").split(" ")[0]||[]._,s.each(function(d){var c=a(this).parent(r);h&&(c=k[h]?a("<div></div>")[k[h]](c):c.filter(":"+h));g&&(c=c.find(g));g&&i&&(c=k[i]?a("<div></div>")[k[i]](c):c.filter(":"+i));var e="CPS"+u++,f=function(b){b&&p[b.type]&&a(c).one(p[b.type],function(){a(c).toggleClass(e)});b&&q[b.type]&&a(c).off(q[b.type]);a(c).toggleClass(e)};d&&(b+=",");b+="."+e;!l?f():a(this).on(v[l]||l,f)})):b+=d;b+=e}a('<style type="text/css">'+b+"</style>").appendTo("head")}};a("link[rel=stylesheet], style").each(function(){a(this).is("link")?a.get(this.href).success(function(a){t(a)}):t(a(this).text())})};a().cssParentSelector()})(jQuery);