11/*
2- *
3- * Spec deoendencies plugin
4- *
5- * @author Roman Alekseev
6- *
7- * */
2+ *
3+ * Spec deoendencies plugin
4+ *
5+ * @author Roman Alekseev
6+ *
7+ * */
88"use strict" ;
99
1010define ( [
1111 'jquery' ,
12- 'modules/module'
13- ] , function ( $ , module ) {
12+ 'modules/module' ,
13+ 'modules/css' ,
14+ 'modules/parseFileTree' ,
15+ 'modules/utils'
16+ ] , function ( $ , module , Css , pft , utils ) {
1417
1518 function SpecDependencies ( ) {
1619 var _this = this ;
1720
21+ var moduleCss = new Css ( "sourcejs-spec-dependencies/css/specDependencies.css" ) ;
22+
1823 this . options . pluginsOptions . specDependencies = $ . extend ( true , {
1924
20- DEPENDENCIES_ROOT_CLASS : "source_dep " ,
21- USED_SPECS_CLASS : "source_used -specs" ,
22- USED_BY_SPECS_CLASS : "source_used -by-specs" ,
25+ DEPENDENCIES_ROOT_CLASS : "source_deps " ,
26+ USED_SPECS_CLASS : "source_deps_used -specs" ,
27+ USED_BY_SPECS_CLASS : "source_deps_used -by-specs" ,
2328
2429 INFO_FILE : "info.json" ,
2530 URL_TO_DEPENDENCIES_FILE : "/data/spec_dependencies_tree.json" ,
2631
27- FILE_INFO_NOT_FOUND : "File info.json not found." ,
32+ SPEC_INFO_NOT_FOUND : "Information about this spec not found." ,
2833 FILE_TREE_NOT_FOUND : "File spec_dependencies_tree.json not found." ,
2934
3035 USED_SPECS_HEAD : "This spec uses:" ,
31- USED_BY_SPEC_HEAD : "This spec used by:"
36+ USED_BY_SPEC_HEAD : "This spec used by:" ,
37+
38+ tempSpecList : { }
3239
3340 } , this . options . pluginsOptions . specDependencies ) ;
3441
@@ -43,49 +50,45 @@ define([
4350
4451 SpecDependencies . prototype . init = function ( ) {
4552 this . drawUsedSpecs ( ) ;
46- this . drawUsedBySpecs ( ) ;
53+ this . getDependenciesTreeJSON ( ) ;
4754 } ;
4855
49- SpecDependencies . prototype . getInfoJSON = function ( ) {
50- var INFO_FILE = this . options . pluginsOptions . specDependencies . INFO_FILE ,
51- infoJSON ;
56+ SpecDependencies . prototype . getSpecInfo = function ( ) {
57+ var fileTree = pft . getParsedJSON ( ) ,
58+ currentUrlArr = this . getCurrentUrlPathArray ( ) ,
5259
53- $ . ajax ( {
54- url : INFO_FILE ,
55- dataType : 'json' ,
56- async : false ,
57- success : function ( data ) {
58- infoJSON = data ;
59- }
60- } ) ;
60+ specInfo ;
6161
62- if ( infoJSON ) return infoJSON ;
62+ for ( var i = 0 ; i < currentUrlArr . length ; i ++ ) {
63+ fileTree = fileTree [ currentUrlArr [ i ] ] ;
64+ }
65+
66+ specInfo = fileTree [ "specFile" ] ;
6367
64- console . log ( this . options . pluginsOptions . specDependencies . FILE_INFO_NOT_FOUND ) ;
68+ if ( specInfo ) return specInfo ;
69+
70+ console . log ( this . options . pluginsOptions . specDependencies . SPEC_INFO_NOT_FOUND ) ;
6571 return false ;
6672 } ;
6773
6874 SpecDependencies . prototype . getDependenciesTreeJSON = function ( ) {
6975 var URL_TO_DEPENDENCIES_FILE = this . options . pluginsOptions . specDependencies . URL_TO_DEPENDENCIES_FILE ,
70- jsonTree ;
76+ _this = this ;
7177
7278 $ . ajax ( {
7379 url : URL_TO_DEPENDENCIES_FILE ,
7480 dataType : 'json' ,
75- async : false ,
7681 success : function ( data ) {
77- jsonTree = data ;
82+ _this . getUsedBySpecsList ( data ) ;
83+ } ,
84+ error : function ( ) {
85+ console . log ( _this . options . pluginsOptions . specDependencies . FILE_TREE_NOT_FOUND ) ;
7886 }
7987 } ) ;
80-
81- if ( jsonTree ) return jsonTree ;
82-
83- console . log ( this . options . pluginsOptions . specDependencies . FILE_TREE_NOT_FOUND ) ;
84- return false ;
8588 } ;
8689
8790 SpecDependencies . prototype . getUsedSpecsList = function ( ) {
88- var infoFile = this . getInfoJSON ( ) ,
91+ var infoFile = this . getSpecInfo ( ) ,
8992 specsList ;
9093
9194 if ( infoFile ) {
@@ -96,15 +99,14 @@ define([
9699 return false ;
97100 } ;
98101
99- SpecDependencies . prototype . getUsedBySpecsList = function ( ) {
100- var jsonTree = this . getDependenciesTreeJSON ( ) ,
101- specsList ,
102+ SpecDependencies . prototype . getUsedBySpecsList = function ( jsonTree ) {
103+ var specsList ,
102104 currentUrl = window . location . pathname ;
103105
104106 if ( jsonTree ) {
105107 currentUrl = currentUrl . slice ( 1 , currentUrl . lastIndexOf ( '/' ) ) ;
106108 specsList = jsonTree [ currentUrl ] ;
107- return specsList ;
109+ return this . drawUsedBySpecs ( specsList ) ;
108110 }
109111
110112 return false ;
@@ -124,25 +126,24 @@ define([
124126 title = "" ;
125127
126128 specsList && specsList . forEach ( function ( specUrl ) {
127- specUrl = _this . unifySpecPath ( specUrl ) ;
129+ specUrl = utils . unifySpecPath ( specUrl ) ;
128130 title = _this . getTitleOfSpecByUrl ( specUrl ) ;
129131
130- res += '<a href="' + specUrl + '">' + title + '</a><br/ >' ;
132+ res += '<li>< a href="' + specUrl + '" class="source_a_s source_a_fs-m" >' + title + '</a></li >' ;
131133 } ) ;
132134
133135 if ( $ ( '.' + USED_SPECS_CLASS ) . length === 0 && res != "" ) {
134136 header = '<p>' + HEADER + '</p>' ;
135137 _this . turnOnLayout ( ) ;
136138
137139 $ ( '.' + ROOT_CLASS )
138- . append ( '<p class="' + USED_SPECS_CLASS + '">' + header + res + '</p >' ) ;
140+ . append ( header + '<ul class="' + USED_SPECS_CLASS + '">' + res + '</ul >' ) ;
139141 }
140142 } ;
141143
142144 // Specs that use current spec
143- SpecDependencies . prototype . drawUsedBySpecs = function ( ) {
145+ SpecDependencies . prototype . drawUsedBySpecs = function ( specsList ) {
144146 var _this = this ,
145- specsList = this . getUsedBySpecsList ( ) ,
146147
147148 USED_BY_SPECS_CLASS = this . options . pluginsOptions . specDependencies . USED_BY_SPECS_CLASS ,
148149 ROOT_CLASS = this . options . pluginsOptions . specDependencies . DEPENDENCIES_ROOT_CLASS ,
@@ -153,18 +154,18 @@ define([
153154 title = "" ;
154155
155156 specsList && specsList . forEach ( function ( specUrl ) {
156- specUrl = _this . unifySpecPath ( specUrl ) ;
157+ specUrl = utils . unifySpecPath ( specUrl ) ;
157158 title = _this . getTitleOfSpecByUrl ( specUrl ) ;
158159
159- res += '<a href="' + specUrl + '">' + title + '</a><br />' ;
160+ res += '<li>< a href="' + specUrl + '" class="source_a_s source_a_fs-m" >' + title + '</a><li />' ;
160161 } ) ;
161162
162163 if ( $ ( '.' + USED_BY_SPECS_CLASS ) . length === 0 && res != "" ) {
163164 header = '<p>' + HEADER + '</p>' ;
164165 _this . turnOnLayout ( ) ;
165166
166167 $ ( '.' + ROOT_CLASS )
167- . append ( '<p class="' + USED_BY_SPECS_CLASS + '">' + header + res + '</p >' ) ;
168+ . append ( header + '<ul class="' + USED_BY_SPECS_CLASS + '">' + res + '</ul >' ) ;
168169 }
169170 } ;
170171
@@ -178,28 +179,36 @@ define([
178179 } ;
179180
180181 SpecDependencies . prototype . getTitleOfSpecByUrl = function ( url ) {
181- var INFO_FILE = this . options . pluginsOptions . specDependencies . INFO_FILE ,
182- title = "" ;
182+ var fileTree = pft . getParsedJSON ( ) ,
183+ urlArr = this . getCurrentUrlPathArray ( url ) ,
183184
184- $ . ajax ( {
185- url : url + '/' + INFO_FILE ,
186- dataType : 'json' ,
187- async : false ,
188- success : function ( data ) {
189- title = data [ "title" ] ;
190- }
191- } ) ;
185+ title ;
186+
187+ for ( var i = 0 ; i < urlArr . length ; i ++ ) {
188+ fileTree = fileTree [ urlArr [ i ] ] ;
189+ }
190+
191+ title = fileTree [ "specFile" ] [ "title" ] ;
192192
193193 if ( title ) return title ;
194194
195195 return url ;
196196 } ;
197197
198- SpecDependencies . prototype . unifySpecPath = function ( url ) {
199- if ( url . charAt ( 0 ) != "/" ) url = "/" + url ;
200- if ( url . charAt ( url . length - 1 ) == "/" ) url = url . slice ( 0 , - 1 ) ;
198+ SpecDependencies . prototype . getCurrentUrlPath = function ( ) {
199+ var currentUrl = window . location . pathname ;
200+ currentUrl = utils . unifySpecPath ( currentUrl ) ;
201201
202- return url ;
202+ return currentUrl ;
203+ } ;
204+
205+ SpecDependencies . prototype . getCurrentUrlPathArray = function ( urlToProceed ) {
206+ var currentUrl = urlToProceed || this . getCurrentUrlPath ( ) ,
207+ urlArr ;
208+
209+ urlArr = currentUrl . slice ( 1 ) . split ( '/' ) ;
210+
211+ return urlArr ;
203212 } ;
204213
205214 return new SpecDependencies ( ) ;
0 commit comments