Exemplo n.º 1
0
        // TODO: Replace this with response caching https://docs.microsoft.com/en-us/aspnet/core/performance/caching/response?view=aspnetcore-3.1
        //[OutputCache(Order = 1, VaryByParam = "none", Location = OutputCacheLocation.Server, Duration = 5000)]
        public async Task <JavaScriptResult> Application()
        {
            var files = await _runtimeMinifier.GetJsAssetPathsAsync(BackOfficeWebAssets.UmbracoPreviewJsBundleName);

            var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco.preview", _globalSettings, _hostingEnvironment);

            return(new JavaScriptResult(result));
        }
    /// <summary>
    ///     Returns the JavaScript to load the back office's assets
    /// </summary>
    /// <returns></returns>
    public static async Task <string> GetScriptForLoadingBackOfficeAsync(
        this IRuntimeMinifier minifier,
        GlobalSettings globalSettings,
        IHostingEnvironment hostingEnvironment,
        IManifestParser manifestParser)
    {
        var files = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

        foreach (var file in await minifier.GetJsAssetPathsAsync(BackOfficeWebAssets.UmbracoCoreJsBundleName))
        {
            files.Add(file);
        }

        foreach (var file in await minifier.GetJsAssetPathsAsync(BackOfficeWebAssets.UmbracoExtensionsJsBundleName))
        {
            files.Add(file);
        }

        // process the independent bundles
        if (manifestParser.CombinedManifest.Scripts.TryGetValue(BundleOptions.Independent,
                                                                out IReadOnlyList <ManifestAssets>?independentManifestAssetsList))
        {
            foreach (ManifestAssets manifestAssets in independentManifestAssetsList)
            {
                var bundleName =
                    BackOfficeWebAssets.GetIndependentPackageBundleName(manifestAssets, AssetType.Javascript);
                foreach (var asset in await minifier.GetJsAssetPathsAsync(bundleName))
                {
                    files.Add(asset);
                }
            }
        }

        // process the "None" bundles, meaning we'll just render the script as-is
        foreach (var asset in await minifier.GetJsAssetPathsAsync(BackOfficeWebAssets
                                                                  .UmbracoNonOptimizedPackageJsBundleName))
        {
            files.Add(asset);
        }

        var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(
            files,
            "umbraco",
            globalSettings,
            hostingEnvironment);

        result += await GetStylesheetInitializationAsync(minifier, manifestParser);

        return(result);
    }
Exemplo n.º 3
0
        public void Parse_Main()
        {
            var result = BackOfficeJavaScriptInitializer.WriteScript("[World]", "Hello", "Blah");

            Assert.AreEqual(
                @"LazyLoad.js([World], function () {
    //we need to set the legacy UmbClientMgr path
    if ((typeof UmbClientMgr) !== ""undefined"") {
        UmbClientMgr.setUmbracoPath('Hello');
    }

    jQuery(document).ready(function () {

        angular.bootstrap(document, ['Blah']);

    });
});".StripWhitespace(), result.StripWhitespace());
        }