-
Notifications
You must be signed in to change notification settings - Fork 4
/
jquery.group.min.js
19 lines (19 loc) · 3.43 KB
/
jquery.group.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
* jQuery Group Plugin
* Examples and Documentation at
* https://github.com/abrad45/jquery.group.js
* Version 1.4 (19 April 2014 00:03 EDT)
* Copyright (c) 2011-2012 Alexander Bradley
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Requires jQuery 1.4+
* Minified at http://closure-compiler.appspot.com/
*/
(function(e){e.fn.group=function(n){function g(){window.console&&console.log&&console.log("[group] "+Array.prototype.join.call(arguments," "))}function m(a){a.first()[0]===a.last()[0]?a.first().addClass("only-child"):(a.first().addClass("first-child"),a.last().addClass("last-child"));return a}for(var a={},f=0;f<arguments.length;++f){var c=arguments[f];switch(c.constructor){case Object:e.extend(a,c);break;case Boolean:a.classing=c;break;case Number:a.size=Math.ceil(c);break;case String:"."===c.charAt(0)?
a.elem_class=c.substr(1):"#"===c.charAt(0)?a.id_prefix=c.substr(1):a.elem=c}}var c=f=0,h=e(),l=!1,d=/^[A-Za-z][\-A-Za-z0-9_:.]*/,b=e(),b={size:2,elem:"div",elem_class:"group",id_prefix:"",classing:!1};a.size&&isNaN(a.size)&&(g('Oops! "'+a.size+"\" is a pretty terrible group size. We've made it "+b.size+" for you."),a.size=b.size);1===a.size&&(g("You want to wrap with size = 1? Just use .wrap(), man! We've set it to "+b.size+" for you."),a.size=b.size);/^([A-Za-z]+)$/.test(a.elem)||(g('Oops! "'+a.elem+
"\" doesn't appear to be a valid HTML tag. We've set it to "+b.elem+" for you."),a.elem=b.elem);d.test(a.elem_class)||(g('Oops! "'+a.elem_class+"\" doesn't appear to be a valid HTML attribute. We've set elem_class to "+b.elem_class+" for you."),a.elem_class=b.elem_class);a.id_prefix&&0<a.id_prefix.length&&!d.test(a.id_prefix)&&(g('Oops! "'+a.id_prefix+"\" doesn't appear to be a valid HTML attribute. We've set id_prefix to the default [nothing] for you."),a.id_prefix=b.id_prefix);var d=e.extend({},
b,a),k={"class":d.elem_class};this.first().is("li")&&(l=!0,this.first().parent().is("ul")?d.elem="ul":this.first().parent().is("ol")&&(d.elem="ol"),e(this).parent("ul, ol").attr("class")&&(k["class"]=a.elem_class?a.elem_class+" "+e(this).parent().attr("class"):e(this).parent().attr("class")));for(;f<this.length;){for(b=this.eq(f);b.length<d.size;)if(this.eq(f).length&&b.last().parent()[0]===this.eq(f).parent()[0])b=b.add(this.eq(f++));else break;d.id_prefix.length&&(k=e.extend(k,{id:d.id_prefix+c++}));
b=b.wrapAll(e("<"+d.elem+"/>",k));d.classing&&(b=m(b));b=b.parent();l&&(b=b.parent());h=h.add(b)}return l?h.children(":first-child").unwrap():h}})(jQuery);