From 45e77a49037bec363f90ce5ae750889434b930f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 17 Oct 2020 14:42:41 +0300 Subject: [PATCH] Documented ASP.NET Core MVC / Razor Pages UI: JavaScript Resource Loader API --- docs/en/UI/AspNetCore/JavaScript-API/Index.md | 2 +- .../JavaScript-API/ResourceLoader.md | 40 +++++++++++++++++++ docs/en/docs-nav.json | 4 ++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 docs/en/UI/AspNetCore/JavaScript-API/ResourceLoader.md diff --git a/docs/en/UI/AspNetCore/JavaScript-API/Index.md b/docs/en/UI/AspNetCore/JavaScript-API/Index.md index a41b57c80e..3473140392 100644 --- a/docs/en/UI/AspNetCore/JavaScript-API/Index.md +++ b/docs/en/UI/AspNetCore/JavaScript-API/Index.md @@ -12,7 +12,7 @@ ABP provides a set of JavaScript APIs for ASP.NET Core MVC / Razor Pages applica * [Features](Features.md) * [Localization](Localization.md) * [Logging](Logging.md) -* ResourceLoader +* [ResourceLoader](ResourceLoader.md) * [Settings](Settings.md) * [UI Block/Busy](Block-Busy.md) * [UI Message](Message.md) diff --git a/docs/en/UI/AspNetCore/JavaScript-API/ResourceLoader.md b/docs/en/UI/AspNetCore/JavaScript-API/ResourceLoader.md new file mode 100644 index 0000000000..1e1c2f9d6d --- /dev/null +++ b/docs/en/UI/AspNetCore/JavaScript-API/ResourceLoader.md @@ -0,0 +1,40 @@ +# ASP.NET Core MVC / Razor Pages UI: JavaScript Resource Loader API + +`abp.ResourceLoader` is a service that can load a JavaScript or CSS file on demand. It guarantees to load the file only once even if you request multiple times. + +## Loading Script Files + +`abp.ResourceLoader.loadScript(...)` function **loads** a JavaScript file from the server and **executes** it. + +**Example: Load a JavaScript file** + +````js +abp.ResourceLoader.loadScript('/Pages/my-script.js'); +```` + +### Parameters + +`loadScript` function can get three parameters; + +* `url` (required, `string`): The URL of the script file to be loaded. +* `loadCallback` (optional, `function`): A callback function that is called once the script is loaded & executed. In this callback you can safely use the code in the script file. This callback is called even if the file was loaded before. +* `failCallback` (optional, `function`): A callback function that is called if loading the script fails. + +**Example: Provide the `loadCallback` argument** + +```` +abp.ResourceLoader.loadScript('/Pages/my-script.js', function() { + console.log('successfully loaded :)'); +}); +```` + +## Loading Style Files + +`abp.ResourceLoader.loadStyle(...)` function adds a `link` element to the `head` of the document for the given URL, so the CSS file is automatically loaded by the browser. + +**Example: Load a CSS file** + +````js +abp.ResourceLoader.loadStyle('/Pages/my-styles.css'); +```` + diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index 14eedc65e7..f51835a5f7 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -498,6 +498,10 @@ { "text": "Logging", "path": "UI/AspNetCore/JavaScript-API/Logging.md" + }, + { + "text": "Resource Loader", + "path": "UI/AspNetCore/JavaScript-API/ResourceLoader.md" } ] },