Exemplo n.º 1
0
        /// <summary>Registers a script block on a page.</summary>
        /// <param name="page">The page onto which to added the script.</param>
        /// <param name="script">The script to add.</param>
        /// <param name="position">Where to add the script.</param>
        /// <param name="options">Script registration options.</param>
        public static void JavaScript(Page page, string script, ScriptPosition position, ScriptOptions options)
        {
            if (page == null) throw new ArgumentNullException("page");

            if (position == ScriptPosition.Header)
            {
                JavaScript(page, script, options);
            }
            else if (position == ScriptPosition.Bottom)
            {
                string key = script.GetHashCode().ToString();
                if (Is(options, ScriptOptions.None))
                    page.ClientScript.RegisterClientScriptBlock(typeof (Register), key, script);
                else if (Is(options, ScriptOptions.ScriptTags))
                    page.ClientScript.RegisterClientScriptBlock(typeof (Register), key, script, true);
                else if (Is(options, ScriptOptions.DocumentReady))
                {
                    JQuery(page);
                    page.ClientScript.RegisterClientScriptBlock(typeof (Register), key, EmbedDocumentReady(script), true);
                }
                else if (Is(options, ScriptOptions.Include))
                    page.ClientScript.RegisterClientScriptInclude(key, page.Engine().ManagementPaths.ResolveResourceUrl(script));
                else
                    throw new ArgumentException("options");
            }
            else
                throw new ArgumentException("position");
        }
Exemplo n.º 2
0
        private static Control AddScriptInclude(Page page, string resourceUrl, Control holder, bool priority)
        {
            if (page == null) throw new ArgumentNullException("page");

            HtmlGenericControl script = new HtmlGenericControl("script");
            page.Items[resourceUrl] = script;

            resourceUrl = page.Engine().ManagementPaths.ResolveResourceUrl(resourceUrl);

            script.Attributes["src"] = resourceUrl;
            script.Attributes["type"] = "text/javascript";
            if(priority)
                holder.Controls.AddAt(0, script);
            else
                holder.Controls.Add(script);

            return script;
        }
Exemplo n.º 3
0
 public static void TinyMCE(Page page)
 {
     JavaScript(page, page.Engine().ManagementPaths.ResolveResourceUrl("{ManagementUrl}/Resources/tiny_mce/tiny_mce.js"));
 }
Exemplo n.º 4
0
        public static void TabPanel(Page page, string selector, bool registerTabCss)
        {
            var key = "N2.Resources.TabPanel" + selector;
            if (page.Items[key] == null)
            {
                JQuery(page);
                JQueryPlugins(page);

                string script = string.Format(tabPanelFormat, selector, selector.Replace('.', '_'));
                JavaScript(page, script, ScriptOptions.DocumentReady);
                page.Items[key] = new object();
                if (registerTabCss)
                {
                    StyleSheet(page, page.Engine().ManagementPaths.ResolveResourceUrl("{ManagementUrl}/Resources/Css/TabPanel.css"));
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>Register a style sheet reference in the page's header with media type.</summary>
        /// <param name="page">The page onto which to register the style sheet.</param>
        /// <param name="resourceUrl">The url to the style sheet to register.</param>
        /// <param name="media">The media type to assign, e.g. print.</param>
        public static void StyleSheet(Page page, string resourceUrl, Media media)
        {
            if (page == null) throw new ArgumentNullException("page");
            if (resourceUrl == null) throw new ArgumentNullException("resourceUrl");

            resourceUrl = N2.Web.Url.ToAbsolute(resourceUrl);

            if (page.Items[resourceUrl] == null)
            {
                PlaceHolder holder = GetPlaceHolder(page);

                HtmlLink link = new HtmlLink();
                link.Href = page.Engine().ManagementPaths.ResolveResourceUrl(resourceUrl);
                link.Attributes["type"] = "text/css";
                link.Attributes["media"] = media.ToString().ToLower();
                link.Attributes["rel"] = "stylesheet";
                holder.Controls.Add(link);

                page.Items[resourceUrl] = null;
            }
        }
Exemplo n.º 6
0
 public static void JQueryPlugins(Page page)
 {
     JQuery(page);
     JavaScript(page, page.Engine().ManagementPaths.ResolveResourceUrl("{ManagementUrl}/Resources/Js/plugins.ashx?v=" + typeof(Register).Assembly.GetName().Version));
 }