示例#1
0
        /// <summary>
        /// Registers the jQuery script library.
        /// </summary>
        private static void RegisterJQuery()
        {
            string jqueryUrl;

            // Check if override file is set ?
            if (Config.JQueryOverrideFile.IsSet())
            {
                jqueryUrl = !Config.JQueryOverrideFile.StartsWith("http") && !Config.JQueryOverrideFile.StartsWith("//")
                    ? BoardInfo.GetURLToScripts(Config.JQueryOverrideFile)
                    : Config.JQueryOverrideFile;
            }
            else
            {
                jqueryUrl = BoardInfo.GetURLToScripts($"jquery-{Config.JQueryVersion}.min.js");
            }

            // load jQuery
            ScriptManager.ScriptResourceMapping.AddDefinition(
                "jquery",
                new ScriptResourceDefinition
            {
                Path         = jqueryUrl,
                DebugPath    = BoardInfo.GetURLToScripts($"jquery-{Config.JQueryVersion}.js"),
                CdnPath      = $"//code.jquery.com/jquery-{Config.JQueryVersion}.min.js",
                CdnDebugPath = $"//code.jquery.com/jquery-{Config.JQueryVersion}.js",
                CdnSupportsSecureConnection = true,
                LoadSuccessExpression       = "window.jQuery"
            });
        }
示例#2
0
        /// <summary>
        /// The add script reference.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="path">
        /// The path.
        /// </param>
        public void AddScriptReference(string name, string path)
        {
            ScriptManager.ScriptResourceMapping.AddDefinition(
                name,
                new ScriptResourceDefinition
            {
                Path = BoardInfo.GetURLToScripts(path)
            });

            this.AddScriptReference(new ScriptReference {
                Name = name
            });
        }
示例#3
0
        /// <summary>
        /// Handles the PreRender event of the CurrentForumPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void CurrentForumPagePreRender([NotNull] object sender, [NotNull] EventArgs e)
        {
            this.RegisterJQuery();

            if (this.PageContext.Vars.ContainsKey("yafForumExtensions"))
            {
                return;
            }

            var version = this.PageContext.BoardSettings.CdvVersion;

            var forumJsName      = Config.IsDotNetNuke ? "ForumExtensionsDnn" : "ForumExtensions";
            var adminForumJsName = Config.IsDotNetNuke ? "ForumAdminExtensionsDnn" : "ForumAdminExtensions";

            ScriptManager.ScriptResourceMapping.AddDefinition(
                "yafForumAdminExtensions",
                new ScriptResourceDefinition
            {
                Path      = BoardInfo.GetURLToScripts($"jquery.{adminForumJsName}.min.js?v={version}"),
                DebugPath = BoardInfo.GetURLToScripts($"jquery.{adminForumJsName}.js?v={version}")
            });

            ScriptManager.ScriptResourceMapping.AddDefinition(
                "yafForumExtensions",
                new ScriptResourceDefinition
            {
                Path      = BoardInfo.GetURLToScripts($"jquery.{forumJsName}.min.js?v={version}"),
                DebugPath = BoardInfo.GetURLToScripts($"jquery.{forumJsName}.js?v={version}")
            });

            ScriptManager.ScriptResourceMapping.AddDefinition(
                "FileUploadScript",
                new ScriptResourceDefinition
            {
                Path      = BoardInfo.GetURLToScripts("jquery.fileupload.comb.min.js"),
                DebugPath = BoardInfo.GetURLToScripts("jquery.fileupload.comb.js")
            });

            this.PageContext.PageElements.AddScriptReference(
                this.PageContext.CurrentForumPage.IsAdminPage ? "yafForumAdminExtensions" : "yafForumExtensions");

            this.PageContext.Vars["yafForumExtensions"] = true;
        }
示例#4
0
        /// <summary>
        /// Registers the jQuery script library.
        /// </summary>
        private static void RegisterJQuery()
        {
            if (BoardContext.Current.PageElements.PageElementExists("jquery"))
            {
                return;
            }

            var registerJQuery = true;

            const string Key = "JQuery-Javascripts";

            // check to see if DotNetAge is around and has registered jQuery for us...
            if (HttpContext.Current.Items[Key] != null)
            {
                if (HttpContext.Current.Items[Key] is StringCollection collection && collection.Contains("jquery"))
                {
                    registerJQuery = false;
                }
            }
            else if (Config.IsDotNetNuke)
            {
                // latest version of DNN should register jQuery for us...
                registerJQuery = false;
            }

            if (registerJQuery)
            {
                string jqueryUrl;

                // Check if override file is set ?
                if (Config.JQueryOverrideFile.IsSet())
                {
                    jqueryUrl = !Config.JQueryOverrideFile.StartsWith("http") &&
                                !Config.JQueryOverrideFile.StartsWith("//")
                                    ? BoardInfo.GetURLToScripts(Config.JQueryOverrideFile)
                                    : Config.JQueryOverrideFile;
                }
                else
                {
                    jqueryUrl = BoardInfo.GetURLToScripts($"jquery-{Config.JQueryVersion}.min.js");
                }

                // load jQuery
                // element.Controls.Add(ControlHelper.MakeJsIncludeControl(jqueryUrl));
                ScriptManager.ScriptResourceMapping.AddDefinition(
                    "jquery",
                    new ScriptResourceDefinition
                {
                    Path         = jqueryUrl,
                    DebugPath    = BoardInfo.GetURLToScripts($"jquery-{Config.JQueryVersion}.js"),
                    CdnPath      = $"//ajax.aspnetcdn.com/ajax/jQuery/jquery-{Config.JQueryVersion}.min.js",
                    CdnDebugPath = $"//ajax.aspnetcdn.com/ajax/jQuery/jquery-{Config.JQueryVersion}.js",
                    CdnSupportsSecureConnection = BoardContext.Current.Get <HttpRequestBase>().IsSecureConnection,
                    LoadSuccessExpression       = "window.jQuery"
                });

                BoardContext.Current.PageElements.AddScriptReference("jquery");
            }

            BoardContext.Current.PageElements.AddPageElement("jquery");
        }
示例#5
0
        /// <summary>Handles the Load event of the Page control.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // Check if forum is installed
            try
            {
                var boards           = BoardContext.Current.GetRepository <Board>().GetAll();
                var isForumInstalled = boards.Any();
            }
            catch
            {
                // failure... no boards.
                HttpContext.Current.Response.Redirect($"{BoardInfo.ForumClientFileRoot}install/default.aspx");
            }

            var scriptManager = ScriptManager.GetCurrent(this.Page);

            var forum = this.MainContent.FindControl("forum");

            if (forum != null)
            {
                var link = new HtmlLink {
                    Href = "~/Content/Site.css"
                };
                link.Attributes.Add("rel", "stylesheet");
                link.Attributes.Add("type", "text/css");

                this.Page.Header.Controls.Add(link);
            }
            else
            {
                scriptManager.Scripts.Insert(
                    0,
                    new ScriptReference(BoardInfo.GetURLToScripts($"jquery-{Config.JQueryVersion}.min.js")));

                scriptManager.Scripts.Add(
                    new ScriptReference(BoardInfo.GetURLToScripts("jquery.ForumExtensions.min.js")));

                var link = new HtmlLink();

                link.Attributes.Add("rel", "stylesheet");
                link.Attributes.Add("type", "text/css");

                link.Href = BoardContext.Current != null
                    ? BoardContext.Current.Get <ITheme>().BuildThemePath("bootstrap-forum.min.css")
                    : "~/Forum/Content/Themes/yaf/bootstrap-forum.min.css";

                this.Page.Header.Controls.Add(link);

                var linkForum = new HtmlLink {
                    Href = "~/Forum/Content/forum.min.css"
                };
                linkForum.Attributes.Add("rel", "stylesheet");
                linkForum.Attributes.Add("type", "text/css");

                this.Page.Header.Controls.Add(linkForum);

                var bundleReference = new BundleReference {
                    Path = "~/Content/css"
                };

                this.Page.Header.Controls.Add(bundleReference);
            }
        }