< select id = "style" onchange = "filter_changed ()" >
< option value = "" > Style: < / option >
< option > neoclassicism < / option >
< option > postmodern < / option >
< option > pseudo-modern < / option >
< option > neogothic < / option >
< / select >
< div class = "home whiteframe" >
<a class = "url" href = "kirpich.example.com/#rust">
< img class = "image" src = " kirpich.example.com/thmb/rust/rust_vid-1.jpg" / >
< / a >
< div class = "name" >
<a class = "url" href = "kirpich.example.com/#rust">
"Rust"
< / a >
< / div >
< div class = "style" > neoclassicism < / div >
< div class = "wall_material" > ceramic brick insulated with mineral wool < / div >
< div class = "square" > 165.5 < / div >
< div class = "living_space" > 86 < / div >
< div class = "floors" > 2 < / div >
< / div >
function filter_changed ( ) {
var list = document. getElementsByClassName ( "home" ) ;
for ( var i = 0 ; i < list. length ; i ++ )
hide ( list [ i ] , is_filtred ( list [ i ] ) ) ;
}
function is_filtred ( node ) {
if ( no_text ( node , "style" ) ) return true ;
}
function no_text ( node , filter ) {
var style_filter = get ( document. getElementById ( filter ) , [ "value" ] ) ;
var home_style = get ( node. getElementsByClassName ( filter ) , [ 0 , "textContent" ] ) ;
if ( style_filter && ( ! home_style || ( home_style. indexOf ( style_filter ) < 0 ) ) )
return true ;
}
function hide ( node , h ) {
node. style . display = h ? "none" : "block" ;
}
function is_filtred ( node ) {
if ( no_text ( node , "style" ) ) return true ;
if ( compare ( node , "square" ) ) return true ;
}
function compare ( node , filter , comparer ) {
var square_filter = get ( document. getElementById ( filter ) , [ "value" ] ) ;
var home_square = get ( node. getElementsByClassName ( filter ) , [ 0 , "textContent" ] ) ;
if ( square_filter && ! home_square )
return true ;
else if ( square_filter && home_square ) {
square_filter = parseFloat ( square_filter )
home_square = parseFloat ( home_square )
if ( ( ! comparer || comparer == ">" ) ? square_filter > home_square : comparer == "<" ? square_filter < home_square : comparer == "=" ? square_filter ! = home_square : false )
return true ;
}
}
function get ( node , keys ) {
for ( var i = 0 ; ( i < keys. length ) && node ; i ++ )
node = node [ keys [ i ] ] ;
return node
}
.name :: before {
content : "Title:" ;
color : gray ;
}
.style :: before {
content : "Style:" ;
color : gray ;
}
.wall_material :: before {
content : "Wall Material:" ;
color : gray ;
}
.square :: before {
content : "Total area:" ;
color : gray ;
}
.square :: after , .living_space :: after {
content : "sq. m." ;
color : gray ;
}
.floors :: before {
content : "Floors:" ;
color : gray ;
}
.living_space :: before {
content : "Living space:" ;
color : gray ;
}
Source: https://habr.com/ru/post/122554/
All Articles