Skip to content

Commit

Permalink
Knockout: move svg bundle component from creator to library
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Nov 27, 2023
1 parent 7df7267 commit 1ea397a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/entries/knockout-ui-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export * from "../knockout/components/paneldynamic-actions/paneldynamic-actions"
export * from "../knockout/components/brand-info/brand-info";
export * from "../knockout/components/notifier/notifier";
export * from "../knockout/components/loading-indicator/loading-indicator";
export * from "../knockout/svg-bundle";

import * as ko from "knockout";
import { SurveyModel } from "survey-core";
Expand Down
3 changes: 0 additions & 3 deletions src/knockout/kosurvey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export class SurveyImplementor extends ImplementorBase {
);
}
public koEventAfterRender(element: any, survey: any) {
if (survey["needRenderIcons"]) {
SvgRegistry.renderIcons();
}
survey.afterRenderSurvey(element);
}
public dispose(): void {
Expand Down
13 changes: 13 additions & 0 deletions src/knockout/svg-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as ko from "knockout";
import { SvgRegistry } from "survey-core";

ko.components.register("sv-svg-bundle", {
viewModel: {
createViewModel: (params: any, componentInfo: any) => {
const element = componentInfo.element.querySelector && componentInfo.element.querySelector("svg") || componentInfo.element.nextElementSibling;
element.innerHTML = SvgRegistry.iconsRenderedHtml();
return params;
}
},
template: "<svg id='sv-icon-holder-global-container' style=\"display:none\"></svg>"
});
4 changes: 4 additions & 0 deletions src/knockout/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

<script type="text/html" id="survey-content-template">
<div data-bind="css: rootCss, elementStyle: themeVariables">
<!-- ko if: needRenderIcons -->
<!-- ko component: { name: 'sv-svg-bundle'} -->
<!-- /ko -->
<!-- /ko -->
<div data-bind="css: wrapperFormCss">
<!-- ko if: !!renderBackgroundImage -->
<div data-bind="css: css.rootBackgroundImage, elementStyle: backgroundImageStyle"></div>
Expand Down

0 comments on commit 1ea397a

Please sign in to comment.