11/*
22 *
3- * Spec deoendencies plugin
3+ * Spec dependencies plugin
44 *
5- * @author Roman Alekseev
5+ * @author Roman Alekseev [email protected] 66 *
77 * */
88"use strict" ;
@@ -25,21 +25,20 @@ define([
2525 DEPENDENCIES_ROOT_CLASS : "source_deps" ,
2626 USED_SPECS_CLASS : "source_deps_used-specs" ,
2727 USED_BY_SPECS_CLASS : "source_deps_used-by-specs" ,
28+ USED_BY_SPEC_HEAD_LINK_CLASS : "source_deps_h_expand" ,
2829
2930 INFO_FILE : "info.json" ,
3031 URL_TO_DEPENDENCIES_FILE : "/data/spec_dependencies_tree.json" ,
3132
3233 SPEC_INFO_NOT_FOUND : "Information about this spec not found." ,
3334 FILE_TREE_NOT_FOUND : "File spec_dependencies_tree.json not found." ,
3435
35- USED_SPECS_HEAD : "This spec uses:" ,
36- USED_BY_SPEC_HEAD : "This spec used by:" ,
37-
38- tempSpecList : { }
36+ USED_SPECS_HEAD : "Most likely it uses" ,
37+ USED_BY_SPEC_HEAD : "This spec used by"
3938
4039 } , this . options . pluginsOptions . specDependencies ) ;
4140
42- $ ( function ( ) {
41+ $ ( function ( ) {
4342 _this . init ( ) ;
4443 } ) ;
4544
@@ -48,27 +47,66 @@ define([
4847 SpecDependencies . prototype = module . createInstance ( ) ;
4948 SpecDependencies . prototype . constructor = SpecDependencies ;
5049
51- SpecDependencies . prototype . init = function ( ) {
52- this . drawUsedSpecs ( ) ;
53- this . getDependenciesTreeJSON ( ) ;
54- } ;
50+ SpecDependencies . prototype . init = function ( ) {
51+ var _this = this ,
52+ USED_BY_SPECS_CLASS = this . options . pluginsOptions . specDependencies . USED_BY_SPECS_CLASS ,
53+ USED_BY_SPEC_HEAD_LINK_CLASS = this . options . pluginsOptions . specDependencies . USED_BY_SPEC_HEAD_LINK_CLASS ;
5554
56- SpecDependencies . prototype . getSpecInfo = function ( ) {
57- var fileTree = pft . getParsedJSON ( ) ,
58- currentUrlArr = this . getCurrentUrlPathArray ( ) ,
55+ // waiting for template's rendering
56+ setTimeout ( function ( ) {
57+ _this . drawUsedSpecs ( ) ;
58+ _this . getDependenciesTreeJSON ( ) ;
59+ } , 200 ) ;
5960
60- specInfo ;
61+ utils . toggleBlock ( USED_BY_SPEC_HEAD_LINK_CLASS , USED_BY_SPECS_CLASS ) ;
62+ } ;
6163
62- for ( var i = 0 ; i < currentUrlArr . length ; i ++ ) {
63- fileTree = fileTree [ currentUrlArr [ i ] ] ;
64+ // Get classes of all elements inside .source_example
65+ SpecDependencies . prototype . getClassList = function ( ) {
66+ var tags = $ ( '.source_example *' ) ,
67+ classNames = { } ,
68+ classList = [ ] ;
69+
70+ for ( var tg = 0 ; tg < tags . length ; tg ++ ) {
71+ var tag = tags [ tg ] ;
72+
73+ if ( tag . className ) {
74+ var classes = tag . className . split ( " " ) ;
75+ for ( var cn = 0 ; cn < classes . length ; cn ++ ) {
76+ var cName = classes [ cn ] ;
77+ if ( ! classNames [ cName ] && cName . indexOf ( "_" ) == - 1 && cName != "" ) {
78+ classNames [ cName ] = true ;
79+ }
80+ }
81+ }
6482 }
6583
66- specInfo = fileTree [ "specFile" ] ;
84+ for ( var name in classNames ) classList . push ( name ) ;
6785
68- if ( specInfo ) return specInfo ;
86+ return classList ;
87+ } ;
6988
70- console . log ( this . options . pluginsOptions . specDependencies . SPEC_INFO_NOT_FOUND ) ;
71- return false ;
89+ SpecDependencies . prototype . getUsedSpecList = function ( ) {
90+ var specPaths = pft . getAllPages ( ) ,
91+ classList = this . getClassList ( ) ,
92+ specList = [ ] ,
93+ currentSpec = this . getCurrentUrlPath ( ) ;
94+
95+ for ( var cn = 0 ; cn < classList . length ; cn ++ ) {
96+ var cName = classList [ cn ] ;
97+
98+ for ( var specPath in specPaths ) {
99+ if ( currentSpec == utils . unifySpecPath ( specPath ) ) continue ;
100+
101+ var specCat = specPath . slice ( specPath . lastIndexOf ( "/" ) + 1 ) ;
102+
103+ if ( specCat == cName ) {
104+ specList . push ( specPath ) ;
105+ }
106+ }
107+ }
108+
109+ return specList ;
72110 } ;
73111
74112 SpecDependencies . prototype . getDependenciesTreeJSON = function ( ) {
@@ -79,34 +117,21 @@ define([
79117 url : URL_TO_DEPENDENCIES_FILE ,
80118 dataType : 'json' ,
81119 success : function ( data ) {
82- _this . getUsedBySpecsList ( data ) ;
120+ _this . getUsedByspecList ( data ) ;
83121 } ,
84122 error : function ( ) {
85123 console . log ( _this . options . pluginsOptions . specDependencies . FILE_TREE_NOT_FOUND ) ;
86124 }
87125 } ) ;
88126 } ;
89127
90- SpecDependencies . prototype . getUsedSpecsList = function ( ) {
91- var infoFile = this . getSpecInfo ( ) ,
92- specsList ;
93-
94- if ( infoFile ) {
95- specsList = infoFile [ "usedSpecs" ] ;
96- return specsList ;
97- }
98-
99- return false ;
100- } ;
101-
102- SpecDependencies . prototype . getUsedBySpecsList = function ( jsonTree ) {
103- var specsList ,
104- currentUrl = window . location . pathname ;
128+ SpecDependencies . prototype . getUsedByspecList = function ( jsonTree ) {
129+ var specList ,
130+ currentUrl = this . getCurrentUrlPath ( ) ;
105131
106132 if ( jsonTree ) {
107- currentUrl = currentUrl . slice ( 1 , currentUrl . lastIndexOf ( '/' ) ) ;
108- specsList = jsonTree [ currentUrl ] ;
109- return this . drawUsedBySpecs ( specsList ) ;
133+ specList = jsonTree [ currentUrl ] ;
134+ return this . drawUsedBySpecs ( specList ) ;
110135 }
111136
112137 return false ;
@@ -115,7 +140,7 @@ define([
115140 // Specs that used in current spec
116141 SpecDependencies . prototype . drawUsedSpecs = function ( ) {
117142 var _this = this ,
118- specsList = this . getUsedSpecsList ( ) ,
143+ specList = this . getUsedSpecList ( ) ,
119144
120145 USED_SPECS_CLASS = this . options . pluginsOptions . specDependencies . USED_SPECS_CLASS ,
121146 ROOT_CLASS = this . options . pluginsOptions . specDependencies . DEPENDENCIES_ROOT_CLASS ,
@@ -125,7 +150,7 @@ define([
125150 header = "" ,
126151 title = "" ;
127152
128- specsList && specsList . forEach ( function ( specUrl ) {
153+ specList && specList . forEach ( function ( specUrl ) {
129154 specUrl = utils . unifySpecPath ( specUrl ) ;
130155 title = _this . getTitleOfSpecByUrl ( specUrl ) ;
131156
@@ -142,26 +167,27 @@ define([
142167 } ;
143168
144169 // Specs that use current spec
145- SpecDependencies . prototype . drawUsedBySpecs = function ( specsList ) {
170+ SpecDependencies . prototype . drawUsedBySpecs = function ( specList ) {
146171 var _this = this ,
147172
148173 USED_BY_SPECS_CLASS = this . options . pluginsOptions . specDependencies . USED_BY_SPECS_CLASS ,
149174 ROOT_CLASS = this . options . pluginsOptions . specDependencies . DEPENDENCIES_ROOT_CLASS ,
150175 HEADER = this . options . pluginsOptions . specDependencies . USED_BY_SPEC_HEAD ,
176+ USED_BY_SPEC_HEAD_LINK_CLASS = this . options . pluginsOptions . specDependencies . USED_BY_SPEC_HEAD_LINK_CLASS ,
151177
152178 res = "" ,
153179 header = "" ,
154180 title = "" ;
155181
156- specsList && specsList . forEach ( function ( specUrl ) {
182+ specList && specList . forEach ( function ( specUrl ) {
157183 specUrl = utils . unifySpecPath ( specUrl ) ;
158184 title = _this . getTitleOfSpecByUrl ( specUrl ) ;
159185
160186 res += '<li><a href="' + specUrl + '" class="source_a_s source_a_fs-m">' + title + '</a><li/>' ;
161187 } ) ;
162188
163189 if ( $ ( '.' + USED_BY_SPECS_CLASS ) . length === 0 && res != "" ) {
164- header = '<p>' + HEADER + '</p>' ;
190+ header = '<p><a href="#" class=" ' + USED_BY_SPEC_HEAD_LINK_CLASS + '" onclick="return false;">' + HEADER + '</a> </p>' ;
165191 _this . turnOnLayout ( ) ;
166192
167193 $ ( '.' + ROOT_CLASS )
@@ -181,7 +207,6 @@ define([
181207 SpecDependencies . prototype . getTitleOfSpecByUrl = function ( url ) {
182208 var fileTree = pft . getParsedJSON ( ) ,
183209 urlArr = this . getCurrentUrlPathArray ( url ) ,
184-
185210 title ;
186211
187212 for ( var i = 0 ; i < urlArr . length ; i ++ ) {
@@ -206,7 +231,11 @@ define([
206231 var currentUrl = urlToProceed || this . getCurrentUrlPath ( ) ,
207232 urlArr ;
208233
209- urlArr = currentUrl . slice ( 1 ) . split ( '/' ) ;
234+ if ( currentUrl . charAt ( 0 ) == '/' ) {
235+ urlArr = currentUrl . slice ( 1 ) . split ( '/' ) ;
236+ } else {
237+ urlArr = currentUrl . split ( '/' ) ;
238+ }
210239
211240 return urlArr ;
212241 } ;
0 commit comments