@@ -82,6 +82,15 @@ Code.getPage = function () {
82
82
return page ;
83
83
} ;
84
84
85
+ Code . getTags = function ( ) {
86
+ var tags = Code . getStringParamFromUrl ( 'tags' , '' ) . trim ( ) ;
87
+ if ( ! tags . length ) {
88
+ tags = '*' ;
89
+ }
90
+ tags = tags . split ( / \s * , \s * / ) ;
91
+ return tags ;
92
+ } ;
93
+
85
94
Code . getDemoPage = function ( ) {
86
95
var area = document . querySelector ( '#demo-area.show' ) ;
87
96
if ( area ) {
@@ -635,6 +644,44 @@ Code.renderContent = function() {
635
644
}
636
645
} ;
637
646
647
+ Code . filterXML = function ( toolboxXML , property , values ) {
648
+ var categories = slice . call ( toolboxXML . querySelectorAll ( 'category' ) ) ;
649
+ categories . forEach ( function ( cate ) {
650
+ if ( cate . getAttribute ( property ) !== null ) {
651
+ filterTag ( cate ) ;
652
+ }
653
+ } ) ;
654
+
655
+ var blocks = slice . call ( toolboxXML . querySelectorAll ( 'block' ) ) ;
656
+ blocks . forEach ( function ( block ) {
657
+ if ( block . getAttribute ( property ) !== null ) {
658
+ filterTag ( block ) ;
659
+ }
660
+ } ) ;
661
+
662
+ function filterTag ( node ) {
663
+ var vals = node . getAttribute ( property ) . trim ( ) . split ( / \s * , \s * / ) ;
664
+ vals = vals . filter ( function ( tag ) {
665
+ return values . indexOf ( '*' ) !== - 1 || values . indexOf ( tag ) !== - 1 ;
666
+ } ) ;
667
+ if ( ! vals . length ) {
668
+ Code . pruneNode ( node ) ;
669
+ }
670
+ }
671
+
672
+ return toolboxXML ;
673
+ } ;
674
+
675
+ Code . pruneNode = function ( node ) {
676
+ if ( node && node . parentElement ) {
677
+ var parent = node . parentElement ;
678
+ parent . removeChild ( node ) ;
679
+ if ( ! parent . children . length ) {
680
+ Code . pruneNode ( parent ) ;
681
+ }
682
+ }
683
+ } ;
684
+
638
685
Code . getToolBox = function ( toolboxXML ) {
639
686
var categories = slice . call ( toolboxXML . querySelectorAll ( 'category' ) ) . map ( function ( e ) {
640
687
return e . id ;
@@ -1401,7 +1448,7 @@ Promise.all([
1401
1448
} )
1402
1449
] ) . then ( function ( values ) {
1403
1450
Code . renderPage ( values [ 0 ] . body . innerHTML ) ;
1404
- Code . init ( Code . getToolBox ( values [ 1 ] . body . firstChild ) ) ;
1451
+ Code . init ( Code . getToolBox ( Code . filterXML ( values [ 1 ] . body . firstChild , 'tags' , Code . getTags ( ) ) ) ) ;
1405
1452
Code . loadDemoArea ( ) ;
1406
1453
Code . loadGa ( ) ;
1407
1454
Code . ga ( ) ;
0 commit comments