forked from garann/template-chooser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (38 loc) · 1.1 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var chooser = {
choices: []
};
$( function () {
$( "div.criteria" ).on( "click", "fieldset", function() {
var $t = $( this );
if ( $t.hasClass( "off" ) ) {
$t.removeClass( "off" ).addClass( "on" );
} else {
$t.addClass( "off" ).removeClass( "on" );
}
});
$( "div.criteria" ).on( "click", "label", function( e ) {
e.stopPropagation();
var $t = $( this ),
cname = $t.find( "input" ).val(),
sibs = $t.siblings( "label" ),
removeIndex,
classes;
$( sibs ).each( function() {
removeIndex = chooser.choices.indexOf( $( this ).find( "input" ).val() );
if ( removeIndex > -1 ) chooser.choices.splice( removeIndex, 1 );
});
if ( cname.length ) {
if ( cname.indexOf( "." ) > -1 ) {
$.each( cname.split( "." ), function( i, nm ) {
chooser.choices.push( nm );
});
} else {
chooser.choices.push( cname );
}
}
if ( !chooser.choices.length ) return;
classes = chooser.choices.join( "." );
$( "div.engines div:not(." + classes + ")" ).addClass( "remove" ).removeClass( "add" );
$( "div.engines div." + classes ).addClass( "add" ).removeClass( "remove" );
});
});