Skip to content

Commit 375341c

Browse files
committed
Adding load event emit, to prevent scrollToHashFailing
Install inscturctions
1 parent e91a814 commit 375341c

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,25 @@ Spec Dependencies is [SourceJS](http://sourcejs.com) plugin for adding crosslink
66

77
Compatible with SourceJS v0.4+.
88

9+
## Install
10+
11+
To install, run npm in `sourcejs/user` folder:
12+
13+
```
14+
npm install sourcejs-spec-status --save
15+
```
16+
17+
Then run Grunt update in SourceJS root:
18+
19+
```
20+
grunt update
21+
```
22+
23+
After install, entering spec pages you will se prediction box.
24+
925
## How to use
1026

11-
Spec Dependencies automatically predicts all specs, that used in current spec ("most likely it uses" section on the picture above). If you also want to see next section to check which specs use current ("this spec used by"), you have to update info.json of the specs with "usedSpecs" property. Value of "usedSpecs" should be an array even for only element.
27+
Spec Dependencies automatically predicts all specs, that used in current spec by comparing CSS classes names with existing Spec names. If you also want to see next section to check which specs use current ("this spec used by"), you have to update `info.json` of the specs with "usedSpecs" property. Value of "usedSpecs" should be an array even for only element.
1228

1329
```
1430
// info.json of Example spec (/url/to/example/spec)

assets/index.js

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
* */
88
"use strict";
99

10+
// Registering load event
11+
window.source = window.source || {};
12+
window.source.loadEvents = window.source.loadEvents || {};
13+
window.source.loadEvents.specDepencencies = window.source.loadEvents.specDepencencies || {
14+
finishEvent: 'specDepencenciesFinish',
15+
updateEvent: 'specDepencenciesUpdate'
16+
};
17+
1018
define([
1119
'jquery',
1220
'sourceModules/module',
@@ -38,6 +46,8 @@ define([
3846

3947
}, this.options.pluginsOptions.specDependencies);
4048

49+
this.moduleOpts = this.options.pluginsOptions.specDependencies;
50+
4151
$(function() {
4252
_this.init();
4353
});
@@ -49,8 +59,8 @@ define([
4959

5060
SpecDependencies.prototype.init = function() {
5161
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;
62+
USED_BY_SPECS_CLASS = this.moduleOpts.USED_BY_SPECS_CLASS,
63+
USED_BY_SPEC_HEAD_LINK_CLASS = this.moduleOpts.USED_BY_SPEC_HEAD_LINK_CLASS;
5464

5565
// waiting for template's rendering
5666
setTimeout(function() {
@@ -61,6 +71,16 @@ define([
6171
utils.toggleBlock(USED_BY_SPEC_HEAD_LINK_CLASS, USED_BY_SPECS_CLASS);
6272
};
6373

74+
// Let SourceJS know that all DOM operations from this plugins are done
75+
SpecDependencies.prototype.emitFinishEvent = function() {
76+
if (window.CustomEvent) {
77+
new CustomEvent('specDepencenciesFinish');
78+
} else {
79+
var event = document.createEvent('CustomEvent');
80+
event.initCustomEvent('specDepencenciesFinish', true, true);
81+
}
82+
};
83+
6484
// Get classes of all elements inside .source_example
6585
SpecDependencies.prototype.getClassList = function() {
6686
var tags = $('.source_example *'),
@@ -110,28 +130,32 @@ define([
110130
};
111131

112132
SpecDependencies.prototype.getDependenciesTreeJSON = function() {
113-
var URL_TO_DEPENDENCIES_FILE = this.options.pluginsOptions.specDependencies.URL_TO_DEPENDENCIES_FILE,
133+
var URL_TO_DEPENDENCIES_FILE = this.moduleOpts.URL_TO_DEPENDENCIES_FILE,
114134
_this = this;
115135

116136
$.ajax({
117137
url: URL_TO_DEPENDENCIES_FILE,
118138
dataType: 'json',
119139
success: function(data) {
120-
_this.getUsedByspecList(data);
140+
_this.handleDependenciesData(data);
121141
},
122142
error: function() {
123-
console.log(_this.options.pluginsOptions.specDependencies.FILE_TREE_NOT_FOUND);
143+
_this.handleDependenciesData();
124144
}
125145
});
126146
};
127147

128-
SpecDependencies.prototype.getUsedByspecList = function(jsonTree) {
129-
var specList,
130-
currentUrl = this.getCurrentUrlPath();
131-
148+
SpecDependencies.prototype.handleDependenciesData = function(jsonTree) {
132149
if (jsonTree) {
150+
var specList;
151+
var currentUrl = this.getCurrentUrlPath();
152+
133153
specList = jsonTree[currentUrl];
134154
return this.drawUsedBySpecs(specList);
155+
} else {
156+
console.log(this.moduleOpts.FILE_TREE_NOT_FOUND);
157+
158+
this.emitFinishEvent();
135159
}
136160

137161
return false;
@@ -142,9 +166,9 @@ define([
142166
var _this = this,
143167
specList = this.getUsedSpecList(),
144168

145-
USED_SPECS_CLASS = this.options.pluginsOptions.specDependencies.USED_SPECS_CLASS,
146-
ROOT_CLASS = this.options.pluginsOptions.specDependencies.DEPENDENCIES_ROOT_CLASS,
147-
HEADER = this.options.pluginsOptions.specDependencies.USED_SPECS_HEAD,
169+
USED_SPECS_CLASS = this.moduleOpts.USED_SPECS_CLASS,
170+
ROOT_CLASS = this.moduleOpts.DEPENDENCIES_ROOT_CLASS,
171+
HEADER = this.moduleOpts.USED_SPECS_HEAD,
148172

149173
res = "",
150174
header = "",
@@ -170,10 +194,10 @@ define([
170194
SpecDependencies.prototype.drawUsedBySpecs = function(specList) {
171195
var _this = this,
172196

173-
USED_BY_SPECS_CLASS = this.options.pluginsOptions.specDependencies.USED_BY_SPECS_CLASS,
174-
ROOT_CLASS = this.options.pluginsOptions.specDependencies.DEPENDENCIES_ROOT_CLASS,
175-
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,
197+
USED_BY_SPECS_CLASS = this.moduleOpts.USED_BY_SPECS_CLASS,
198+
ROOT_CLASS = this.moduleOpts.DEPENDENCIES_ROOT_CLASS,
199+
HEADER = this.moduleOpts.USED_BY_SPEC_HEAD,
200+
USED_BY_SPEC_HEAD_LINK_CLASS = this.moduleOpts.USED_BY_SPEC_HEAD_LINK_CLASS,
177201

178202
res = "",
179203
header = "",
@@ -193,10 +217,12 @@ define([
193217
$('.' + ROOT_CLASS)
194218
.append(header + '<ul class="' + USED_BY_SPECS_CLASS + '">' + res + '</ul>');
195219
}
220+
221+
this.emitFinishEvent();
196222
};
197223

198224
SpecDependencies.prototype.turnOnLayout = function() {
199-
var ROOT_CLASS = this.options.pluginsOptions.specDependencies.DEPENDENCIES_ROOT_CLASS,
225+
var ROOT_CLASS = this.moduleOpts.DEPENDENCIES_ROOT_CLASS,
200226
SECTION_CLASS = this.options.SECTION_CLASS;
201227

202228
if($('.' + ROOT_CLASS).length === 0) {

0 commit comments

Comments
 (0)