Fix issue where HLJS was not configured when preloaded
Change-Id: Ie8c3d2aaae16ae4361f46372a5ed24ead24fe82e
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
// NOTE: intended singleton.
|
// NOTE: intended singleton.
|
||||||
value: {
|
value: {
|
||||||
|
configured: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
callbacks: [],
|
callbacks: [],
|
||||||
},
|
},
|
||||||
@@ -60,12 +61,13 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getHighlightLib() {
|
_getHighlightLib() {
|
||||||
return window.hljs;
|
const lib = window.hljs;
|
||||||
},
|
if (lib && !this._state.configured) {
|
||||||
|
this._state.configured = true;
|
||||||
|
|
||||||
_configureHighlightLib() {
|
lib.configure({classPrefix: 'gr-diff gr-syntax gr-syntax-'});
|
||||||
this._getHighlightLib().configure(
|
}
|
||||||
{classPrefix: 'gr-diff gr-syntax gr-syntax-'});
|
return lib;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getLibRoot() {
|
_getLibRoot() {
|
||||||
@@ -93,10 +95,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
script.src = src;
|
script.src = src;
|
||||||
script.onload = function() {
|
script.onload = resolve;
|
||||||
this._configureHighlightLib();
|
script.onerror = reject;
|
||||||
resolve();
|
|
||||||
}.bind(this);
|
|
||||||
Polymer.dom(document.head).appendChild(script);
|
Polymer.dom(document.head).appendChild(script);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@@ -55,6 +55,7 @@ limitations under the License.
|
|||||||
loadStub.restore();
|
loadStub.restore();
|
||||||
|
|
||||||
// Because the element state is a singleton, clean it up.
|
// Because the element state is a singleton, clean it up.
|
||||||
|
element._state.configured = false;
|
||||||
element._state.loading = false;
|
element._state.loading = false;
|
||||||
element._state.callbacks = [];
|
element._state.callbacks = [];
|
||||||
});
|
});
|
||||||
@@ -88,8 +89,13 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite('preloaded', () => {
|
suite('preloaded', () => {
|
||||||
|
let hljsStub;
|
||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
window.hljs = 'test-object';
|
hljsStub = {
|
||||||
|
configure: sinon.stub(),
|
||||||
|
};
|
||||||
|
window.hljs = hljsStub;
|
||||||
});
|
});
|
||||||
|
|
||||||
teardown(() => {
|
teardown(() => {
|
||||||
@@ -101,7 +107,14 @@ limitations under the License.
|
|||||||
element.get().then(firstCallHandler);
|
element.get().then(firstCallHandler);
|
||||||
flush(() => {
|
flush(() => {
|
||||||
assert.isTrue(firstCallHandler.called);
|
assert.isTrue(firstCallHandler.called);
|
||||||
assert.isTrue(firstCallHandler.calledWith('test-object'));
|
assert.isTrue(firstCallHandler.calledWith(hljsStub));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('configures hljs', done => {
|
||||||
|
element.get().then(() => {
|
||||||
|
assert.isTrue(window.hljs.configure.calledOnce);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user