Beispiel #1
0
        private static void RegisterJsIncludes(string innerHtml, ClientDependencyLoader loader)
        {
            var tagPattern = string.Format(TagPattern, "script");
            var typeAttributePattern = string.Format(AttributePattern, "type");
            var srcAttributePattern = string.Format(AttributePattern, "src");

            var count = 0;
            foreach (Match match in Regex.Matches(innerHtml, tagPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                var typeMatch = Regex.Match(match.Value, typeAttributePattern,
                                            RegexOptions.Compiled | RegexOptions.IgnoreCase |
                                            RegexOptions.CultureInvariant);

                if (typeMatch.Success && typeMatch.Groups["val"].Value == "text/javascript")
                {
                    var srcMatch = Regex.Match(match.Value, srcAttributePattern,
                                            RegexOptions.Compiled | RegexOptions.IgnoreCase |
                                            RegexOptions.CultureInvariant);

                    if (srcMatch.Success)
                    {
                        loader.RegisterDependency(DefaultPriority + count,
                            srcMatch.Groups["val"].Value,
                            ClientDependencyType.Javascript);

                        count++;
                    }
                }
            }
        }
Beispiel #2
0
 private void RegisterIncludes(IEnumerable<BasicFile> files, ClientDependencyLoader loader, ClientDependencyType dependencyType)
 {
     foreach (var file in files)
     {
         loader.RegisterDependency(file.Group, file.Priority, file.FilePath, "", dependencyType, file.HtmlAttributes, file.ForceProvider);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            var http = new HttpContextWrapper(Context);

            //dynamically register the dependency
            ClientDependencyLoader.GetInstance(http).RegisterDependency("Content.css", "Styles", ClientDependencyType.Css);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var http = new HttpContextWrapper(Context);

            var embeddedCssPath = Page.ClientScript.GetWebResourceUrl(typeof(EmbeddedResourceTest), "ClientDependency.Web.Test.Pages.embedded.css");

            //embed the web resource! sweeet.
            ClientDependencyLoader.GetInstance(http).RegisterDependency(embeddedCssPath, Core.ClientDependencyType.Css);
        }
Beispiel #5
0
 /// <summary>Initializes a new instance of the <see cref="ViewJackrabbitPresenter" /> class.</summary>
 /// <param name="view">The view.</param>
 /// <param name="repository">The repository.</param>
 internal ViewJackrabbitPresenter(IViewJackrabbitView view, IRepository repository)
     : base(view)
 {
     this.repository         = repository;
     this.dependencyLoader   = new Lazy <ClientDependencyLoader>(() => ClientDependencyLoader.GetInstance(this.HttpContext));
     this.View.Initialize   += this.View_Initialize;
     this.View.AddScript    += this.View_AddScript;
     this.View.UpdateScript += this.View_UpdateScript;
     this.View.DeleteScript += this.View_DeleteScript;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            var http = new HttpContextWrapper(Context);

            //Changes the provider to be used at runtime
            ClientDependencyLoader.GetInstance(http).ProviderName = LazyLoadProvider.DefaultName;

            //dynamically register the dependency
            ClientDependencyLoader.GetInstance(http).RegisterDependency("Content.css", "Styles", ClientDependencyType.Css);
        }
Beispiel #7
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.CssClass = "xpath-templatable-list-wrapper";

            this.EnsureChildControls();

            if (!this.Page.IsPostBack)
            {
                this.selectedItemsHiddenField.Value = this.data.Value.ToString();
            }

            this.PopulateSourceList();

            // add custom css from options
            if (!string.IsNullOrWhiteSpace(this.options.CssFile))
            {
                ClientDependencyLoader clientDependencyLoader = ClientDependencyLoader.GetInstance(new HttpContextWrapper(HttpContext.Current));
                clientDependencyLoader.RegisterDependency(this.options.CssFile, ClientDependency.Core.ClientDependencyType.Css);
            }

            // add datatype css / js
            this.RegisterEmbeddedClientResource("uComponents.DataTypes.XPathTemplatableList.XPathTemplatableList.css", ClientDependencyType.Css);
            this.RegisterEmbeddedClientResource("uComponents.DataTypes.XPathTemplatableList.XPathTemplatableList.js", ClientDependencyType.Javascript);

            // if selecting a js file, it'll read in the contents of that file server side, and pass that string as a callback to the datatype init function
            string customCallbackScript = null;

            if (!string.IsNullOrWhiteSpace(this.options.ScriptFile))
            {
                string scriptFile = HostingEnvironment.MapPath("~" + this.options.ScriptFile);
                if (scriptFile != null)
                {
                    customCallbackScript = File.ReadAllText(scriptFile);
                }
            }

            if (string.IsNullOrWhiteSpace(customCallbackScript))
            {
                customCallbackScript = "null"; // ensure a clean js method call
            }

            string startupScript = @"
                <script language='javascript' type='text/javascript'>
                    $(document).ready(function () {
                        XPathTemplatableList.init(jQuery('div#" + this.div.ClientID + "'), " + customCallbackScript + @");
                    });
                </script>";

            ScriptManager.RegisterStartupScript(this, typeof(XPathTemplatableListDataEditor), this.ClientID + "_init", startupScript, false);
        }
        /// <summary>
        /// Registers the dependencies as controls of the placeholder controls specified
        /// </summary>
        /// <param name="http"></param>
        /// <param name="js"></param>
        /// <param name="css"></param>
        /// <remarks>
        /// For some reason ampersands that aren't html escaped are not compliant to HTML standards when they exist in 'link' or 'script' tags in URLs,
        /// we need to replace the ampersands with &amp; . This is only required for this one w3c compliancy, the URL itself is a valid URL.
        /// </remarks>
        protected override void RegisterDependencies(HttpContextBase http, string js, string css)
        {
            var jsPlaceholder = ClientDependencyLoader.GetInstance(http).Page.FlattenChildren()
                                .FirstOrDefault(x => x.ID == JavaScriptPlaceHolderId);

            if (jsPlaceholder == null || (!(jsPlaceholder is PlaceHolder)))
            {
                throw new NullReferenceException("Could not find the placeholder control to render the JavaScript:" + JavaScriptPlaceHolderId);
            }
            AddToControl(http, js.Replace("&", "&amp;"), jsPlaceholder);

            var cssPlaceholder = ClientDependencyLoader.GetInstance(http).Page.FlattenChildren()
                                 .FirstOrDefault(x => x.ID == CssPlaceHolderId);

            if (cssPlaceholder == null || (!(cssPlaceholder is PlaceHolder)))
            {
                throw new NullReferenceException("Could not find the placeholder control to render the CSS:" + CssPlaceHolderId);
            }
            AddToControl(http, css.Replace("&", "&amp;"), cssPlaceholder);
        }
Beispiel #9
0
        private static void AddToControl(HttpContextBase http, string literal)
        {
            var dCtl = new LiteralControl(literal);

            ClientDependencyLoader.GetInstance(http).Controls.Add(dCtl);
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     //dynamically change the provider for this page
     ClientDependencyLoader.GetInstance(new HttpContextWrapper(this.Context))
     .ProviderName = "LoaderControlProvider";
 }
Beispiel #11
0
 private static void RegisterIncludes(string innerHtml, ClientDependencyLoader loader)
 {
     RegisterCssIncludes(innerHtml, loader);
     RegisterJsIncludes(innerHtml, loader);
 }
Beispiel #12
0
 private void RegisterIncludes(string innerHtml, ClientDependencyLoader loader)
 {
     RegisterIncludes(GetIncludes(innerHtml, ClientDependencyType.Css), loader, ClientDependencyType.Css);
     RegisterIncludes(GetIncludes(innerHtml, ClientDependencyType.Javascript), loader, ClientDependencyType.Javascript);
 }