Skip to content

Commit e9e02cc

Browse files
Jeremy ColemanJeremy Coleman
authored andcommitted
Committed load function updates
1 parent a08182b commit e9e02cc

File tree

1 file changed

+61
-34
lines changed

1 file changed

+61
-34
lines changed

src/webparts/trueScriptEditor/TrueScriptEditorWebPart.ts

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,50 @@ import { ITrueScriptEditorWebPartProps } from './ITrueScriptEditorWebPartProps';
1313
import * as jQuery from 'jQuery';
1414
export default class TrueScriptEditorWebPart extends BaseClientSideWebPart<ITrueScriptEditorWebPartProps> {
1515

16+
private hasLoaded: boolean = false;
17+
1618
public render(): void {
1719
window['trueScriptEditor'] = this;
18-
window['jQuery'] = jQuery;
19-
var loaded = [];
20-
jQuery('head').append('<style truescript></style>');
21-
jQuery('link[truescript]').each(function(){ jQuery(this).remove(); });
22-
jQuery(this.domElement).empty();
23-
if (this.properties.cssEditor || this.properties.extCSS || this.properties.extJS || this.properties.scriptEditor || this.properties.htmlEditor) {
24-
if (this.properties.scriptEditor){
25-
window['jQuery'] = jQuery;
26-
eval(this.properties.scriptEditor);
27-
}
28-
if (this.properties.extJS){
29-
this.properties.extJS.split(',').forEach(function(scr){
30-
if (loaded.indexOf(scr) <= -1){
31-
loaded.push(scr);
32-
window['jQuery'].getScript(scr);
33-
}
34-
});
35-
}
36-
if (this.properties.cssEditor){
37-
jQuery('style[truescript]').empty().html(this.properties.cssEditor);
38-
}
39-
if (this.properties.extCSS){
40-
jQuery('link[truescript]').each(function(){
41-
jQuery(this).remove();
42-
});
43-
this.properties.extCSS.split(',').forEach(function(css){
44-
jQuery('head').append('<link truescript rel="stylesheet" href="' + css + '" type="text/css" />');
45-
});
46-
}
47-
if (this.properties.htmlEditor){
48-
jQuery(this.domElement).html(this.properties.htmlEditor);
49-
}
50-
} else {
20+
window['jQuery'] = jQuery;
21+
var loaded = [];
22+
jQuery('head').append('<style truescript></style>');
23+
jQuery('link[truescript]').each(function () { jQuery(this).remove(); });
24+
jQuery(this.domElement).empty();
25+
if (!this.hasLoaded && (this.properties.cssEditor || this.properties.extCSS || this.properties.extJS || this.properties.scriptEditor || this.properties.htmlEditor)) {
26+
if (jQuery('#spPropertyPaneContainer button[aria-label=Close]').attr('tabindex') != "0") {
27+
this.hasLoaded = true;
28+
if (this.properties.extJS || this.properties.scriptEditor) {
29+
window['jQuery'] = jQuery;
30+
var extJS = this.properties.extJS.split(',');
31+
if (this.properties.extJS) {
32+
this.getScript(extJS, function () {
33+
if (window['trueScriptEditor'].properties.scriptEditor) {
34+
eval(window['trueScriptEditor'].properties.scriptEditor);
35+
}
36+
});
37+
}
38+
else {
39+
if (this.properties.scriptEditor) {
40+
eval(window['trueScriptEditor'].properties.scriptEditor);
41+
}
42+
}
43+
}
44+
if (this.properties.cssEditor) {
45+
jQuery('style[truescript]').empty().html(this.properties.cssEditor);
46+
}
47+
if (this.properties.extCSS) {
48+
jQuery('link[truescript]').each(function () {
49+
jQuery(this).remove();
50+
});
51+
this.properties.extCSS.split(',').forEach(function (css) {
52+
jQuery('head').append('<link truescript rel="stylesheet" href="' + css + '" type="text/css" />');
53+
});
54+
}
55+
if (this.properties.htmlEditor) {
56+
jQuery(this.domElement).html(this.properties.htmlEditor);
57+
}
58+
}
59+
} else if (!this.hasLoaded) {
5160
this.domElement.innerHTML = `
5261
<div class="${styles.helloWorld}">
5362
<div class="${styles.container}">
@@ -67,14 +76,32 @@ export default class TrueScriptEditorWebPart extends BaseClientSideWebPart<ITrue
6776

6877
}
6978

79+
private getScript(scrArr, callback) {
80+
var ind = 0;
81+
scrArr.forEach(function (scr) {
82+
window['jQuery'].getScript(scr, function () {
83+
if (++ind == scrArr.length) {
84+
callback();
85+
}
86+
});
87+
});
88+
}
89+
7090
public editProperties(){
7191
this.context.propertyPane.open();
7292
}
7393

7494
protected get dataVersion(): Version {
7595
return Version.parse('1.0');
7696
}
77-
97+
protected onPropertyPaneConfigurationComplete() {
98+
this.render();
99+
};
100+
protected onPropertyPaneFieldChanged(propertyPath, oldValue, newValue) {
101+
if (oldValue != newValue) {
102+
this.hasLoaded = false;
103+
}
104+
};
78105
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
79106
return {
80107
pages: [

0 commit comments

Comments
 (0)