Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dallas 5 posts 74 karma points c-trib
    Sep 26, 2018 @ 07:33
    Dallas
    0

    assetsService.loadCss Ignores Attributes parameter

    I'm modifying a custom Property Editor and I require the ability to inject a stylesheet with custom attributes.

    I'm using the umbraco.services.js module's assetsService.

    Documentation for this service is provided here:

    https://our.umbraco.com/apidocs/ui/#/api/umbraco.services.assetsService

    I'm using the loadCss method, attempting to pass it an attribute as laid out below:

    assetsService.loadCss("style.css", $scope, { crossorigin: 'anonymous' }, 10000 )
    

    The stylesheet is being added to the page but without the attribute that I require:

    <link href="styles.css" rel="stylesheet" class="lazyload" charset="utf-8">
    

    Checking the umbraco.services.js module, it seems to be ignoring the attributes parameter within the loadCss method:

    loadCss: function (path, scope, attributes, timeout) {
                    path = convertVirtualPath(path);
                    var asset = this._getAssetPromise(path);
                    // $q.defer();
                    var t = timeout || 5000;
                    var a = attributes || undefined;
                    if (asset.state === 'new') {
                        asset.state = 'loading';
                        LazyLoad.css(appendRnd(path), function () {
                            if (!scope) {
                                asset.state = 'loaded';
                                asset.deferred.resolve(true);
                            } else {
                                asset.state = 'loaded';
                                angularHelper.safeApply(scope, function () {
                                    asset.deferred.resolve(true);
                                });
                            }
                        });
                    } else if (asset.state === 'loaded') {
                        asset.deferred.resolve(true);
                    }
                    return asset.deferred.promise;
                }
    

    I think this could be a bug with Umbraco but I thought I'd run it by here before raising an issue on GitHub. Has anybody here had experience with applying custom attributes using assetsServices.loadCss ?

    Thanks in advance!

  • Dave Woestenborghs 3213 posts 10799 karma points MVP 4x admin c-trib
    Sep 26, 2018 @ 08:02
    Dave Woestenborghs
    1

    I think the attribute parameter is not working since a very long time.

    If you take a look at this commit : https://github.com/umbraco/Umbraco-CMS/commit/90bf6003786cb6bd1c7ff94c48102fa3d1998f6a#diff-ca9e001eb1d67c6dccdfdd7aeff07f77

    You will see they changed the way assets are loaded (from yepnope to LazyLoad)

    So it would be good to raise a issue.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft