Exemplo n.º 1
0
        public static string RegisterScriptBundle(
            this IClientScriptRegistry clientScriptRegistry,
            HttpContextBase httpContext,
            string bundleUrl,
            IEnumerable <string> urls,
            IEnumerable <string> sharedDependencies = null)
        {
            if (urls == null || !urls.Any())
            {
                return(string.Empty);
            }

            // Enforce the provided ordering within a registration
            // by making each item in the bundle depend on the previous.
            var    resources = new List <ClientScriptResource>();
            string lastUrl   = null;

            foreach (var url in urls)
            {
                resources.Add(new BundledScriptReferenceClientResource(
                                  url,
                                  bundleUrl,
                                  new[] { lastUrl }.Concat(sharedDependencies ?? Enumerable.Empty <string>())));

                lastUrl = url;
            }

            var output = clientScriptRegistry.Register(httpContext, resources);

            return(string.Concat(output));
        }
Exemplo n.º 2
0
        public static string RegisterInlineScript(
            this IClientScriptRegistry clientScriptRegistry,
            HttpContextBase httpContext,
            string content,
            string name       = null,
            bool addScriptTag = false,
            IEnumerable <string> dependencies = null)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                return(string.Empty);
            }

            var resource = new InlineScriptClientResource(
                content: content,
                name: name,
                addScriptTag: addScriptTag,
                requirements: dependencies);

            var output = clientScriptRegistry.Register(
                httpContext,
                new[] { resource });

            return(string.Concat(output));
        }
Exemplo n.º 3
0
        public static string RegisterScriptReference(
            this IClientScriptRegistry clientScriptRegistry,
            HttpContextBase httpContext,
            string url,
            bool async = false,
            IEnumerable <string> dependencies = null)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(string.Empty);
            }

            var resource = new ScriptReferenceClientResource(url, async, dependencies);

            var output = clientScriptRegistry.Register(
                httpContext,
                new[] { resource });

            return(string.Concat(output));
        }