Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatthes committed Oct 19, 2023
1 parent 1fffa91 commit c2d9b39
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@leuffen/jodastyle",
"version": "3.0.5",
"version": "3.0.6",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.module.js",
Expand Down
6 changes: 6 additions & 0 deletions src/component/joda-content-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getCurrentBreakpoint, Jodaresponsive} from "../processor/jodaresponsive"
import {Logger} from "../helper/logger";
import {Jodavisualize} from "../processor/jodavisualize";
import {jodaSiteConfig} from "../helper/JodaSiteConfig";
import {allTemplatesConnectedCallbacks} from "../helper/functions";


function getCSSRule(ruleName : string) : CSSStyleRule {
Expand Down Expand Up @@ -110,6 +111,11 @@ export class JodaContentElement extends HTMLElement {
jodaresponsive.process(this as HTMLElement);

});

// Run all allTemplateConnectedCallbacks registered
for(let callback of allTemplatesConnectedCallbacks) {
await callback();
}
}


Expand Down
19 changes: 19 additions & 0 deletions src/helper/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {QTemplate, template_parse} from "./QTemplate";
import {Joda} from "../joda";



export let allTemplatesConnectedCallbacks : any[] = [];


export async function await_property(object : object, property : string[] | string, wait : number = 10) {
if (typeof property === "string") {
property = property.split(".");
Expand Down Expand Up @@ -267,5 +271,20 @@ export async function getTemplateFilledWithContent(templateSelector : string, co
content.remove();
}



return clone;
}



export async function runCallbacksForTemplate(templateSelector: string , element : HTMLElement) {
let templateConfig = Joda.getRegisteredTemplate(templateSelector);
if (templateConfig?.callbacks?.onAfterConnectedCallback) {
await templateConfig.callbacks.onAfterConnectedCallback(element as HTMLElement);
}
if (templateConfig?.callbacks?.onAfterAllTemplatesConnectedCallback) {
// Spool up callback (executed by jodastyle)
allTemplatesConnectedCallbacks.push(async() => templateConfig.callbacks.onAfterAllTemplatesConnectedCallback(element as HTMLElement));
}
}
19 changes: 18 additions & 1 deletion src/joda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@

type TemplateCallbacks = {
//onBeforeTemplateLoad?: (template: string, element: HTMLElement) => void,

/**
* Called after the Template was connected (added to DOM)
*
* @param element The root element of the template
*/
onAfterConnectedCallback?: (element: HTMLElement) => void,


/**
* Called after all templates were connected (added to DOM) and initialized.
* Use this Callback to add special functionality to your template
*
* @param element The root element of the template
*/
onAfterAllTemplatesConnectedCallback?: (element: HTMLElement) => void,
}


type TemplateData = {
template: string,
layoutDefaults: {[key: string]: string|number|boolean}
Expand Down
6 changes: 5 additions & 1 deletion src/processor/jodastyle-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
await_property,
getCleanVariableValue,
getTemplateFilledWithContent,
JodaUseRenderer
JodaUseRenderer, runCallbacksForTemplate
} from "../helper/functions";
import {Logger} from "../helper/logger";
import {ka_eval} from "@kasimirjs/embed";
Expand Down Expand Up @@ -61,6 +61,9 @@ jodaStyleCommands["--joda-wrap"] = async (value : string, target, element : HTML
let newElement = await getTemplateFilledWithContent(value, placeholder, element);
placeholder.replaceWith(newElement);

await runCallbacksForTemplate(value, element as HTMLElement);


return element;

} else {
Expand Down Expand Up @@ -176,6 +179,7 @@ jodaStyleCommands["--joda-use"] = async(value : string, target, element : HTMLEl
});
element.parentElement.insertBefore(newElement, element);
element.parentElement.removeChild(element);
await runCallbacksForTemplate(value, firstElement as HTMLElement);
return firstElement;
}

Expand Down

0 comments on commit c2d9b39

Please sign in to comment.