Exemplo n.º 1
0
        /// <summary>
        /// Loads jQuery depending on configuration settings (CDN, WebResource or site url)
        /// and injects the full script link into the page.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="jQueryUrl">Optional url to jQuery as a virtual or absolute server path</param>
        public static void LoadjQuery(Control control, string jQueryUrl)
        {
            ClientScriptProxy p = ClientScriptProxy.Current;

            if (!string.IsNullOrEmpty(jQueryUrl))
            {
                p.RegisterClientScriptInclude(control, typeof(ControlResources), jQueryUrl, ScriptRenderModes.HeaderTop);
            }
            else if (jQueryLoadMode == jQueryLoadModes.WebResource)
            {
                p.RegisterClientScriptResource(control, typeof(ControlResources), ControlResources.JQUERY_SCRIPT_RESOURCE, ScriptRenderModes.HeaderTop);
            }
            else if (jQueryLoadMode == jQueryLoadModes.ContentDeliveryNetwork)
            {
                // Load from CDN Url specified
                p.RegisterClientScriptInclude(control, typeof(ControlResources), jQueryCdnUrl, ScriptRenderModes.HeaderTop);

                // check if jquery loaded - if it didn't we're not online and use WebResource
                string scriptCheck =
                    @"if (typeof(jQuery) == 'undefined')  
        document.write(unescape(""%3Cscript src='{0}' type='text/javascript'%3E%3C/script%3E""));";

                jQueryUrl = p.GetClientScriptResourceUrl(control, typeof(ControlResources),
                                                         ControlResources.JQUERY_SCRIPT_RESOURCE);
                p.RegisterClientScriptBlock(control, typeof(ControlResources),
                                            "jquery_register", string.Format(scriptCheck, jQueryUrl), true,
                                            ScriptRenderModes.HeaderTop);
            }

            return;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Helper function that is used to load script resources for various AJAX controls
        /// Loads a script resource based on the following scriptLocation values:
        ///
        /// * WebResource
        ///   Loads the Web Resource specified out of ControlResources. Specify the resource
        ///   that applied in the resourceName parameter
        ///
        /// * Url/RelativeUrl
        ///   loads the url with ResolveUrl applied
        ///
        /// * empty (no value)
        ///   No action is taken
        /// </summary>
        /// <param name="control">The control instance for which the resource is to be loaded</param>
        /// <param name="scriptLocation">WebResource, a Url or empty (no value)</param>
        /// <param name="resourceName">The name of the resource when WebResource is used for scriptLocation</param>
        /// <param name="topOfHeader">Determines if scripts are loaded into the header whether they load at the top or bottom</param>
        public void LoadControlScript(Control control, string scriptLocation, string resourceName, ScriptRenderModes renderMode)
        {
            ClientScriptProxy proxy = ClientScriptProxy.Current;

            // Specified nothing to do
            if (string.IsNullOrEmpty(scriptLocation))
            {
                return;
            }

            ScriptItem scriptItem = new ScriptItem();

            scriptItem.Src        = scriptLocation;
            scriptItem.RenderMode = renderMode;

            if (scriptLocation == "WebResource")
            {
                scriptItem.Resource         = resourceName;
                scriptItem.ResourceAssembly = null;
                scriptItem.Src = resourceName;
            }

            //// It's a relative url
            //if (ClientScriptProxy.LoadScriptsInHeader)
            //    proxy.RegisterClientScriptIncludeInHeader(control, control.GetType(),
            //                                            control.ResolveUrl(scriptLocation), topOfHeader);
            //else
            //    proxy.RegisterClientScriptInclude(control, control.GetType(),
            //                            Path.GetFileName(scriptLocation), control.ResolveUrl(scriptLocation));

            AddScript(scriptItem);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the appropriate jScript library out of the scripts directory and
        /// injects into a WebForms page.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="jQueryUiUrl">Optional url to jQuery as a virtual or absolute server path</param>
        public static void LoadjQueryUi(Control control, string jQueryUiUrl)
        {
            ClientScriptProxy p = ClientScriptProxy.Current;

            // jQuery UI isn't provided as a Web Resource so default to a fixed URL
            if (jQueryLoadMode == jQueryLoadModes.WebResource)
            {
                //throw new InvalidOperationException(Resources.WebResourceNotAvailableForJQueryUI);
                jQueryUiUrl = UrlUtils.ResolveUrl(jQueryUiLocalFallbackUrl);
            }

            if (!string.IsNullOrEmpty(jQueryUiUrl))
            {
                p.RegisterClientScriptInclude(control, typeof(ControlResources), jQueryUiUrl, ScriptRenderModes.Header);
            }
            else if (jQueryLoadMode == jQueryLoadModes.ContentDeliveryNetwork)
            {
                // Load from CDN Url specified
                p.RegisterClientScriptInclude(control, typeof(ControlResources), jQueryUiCdnUrl, ScriptRenderModes.Header);

                // check if jquery loaded - if it didn't we're not online and use WebResource
                string scriptCheck =
                    @"if (typeof(jQuery.ui) == 'undefined')  
        document.write(unescape(""%3Cscript src='{0}' type='text/javascript'%3E%3C/script%3E""));";

                p.RegisterClientScriptBlock(control,
                                            typeof(ControlResources), "jquery_ui",
                                            string.Format(scriptCheck, UrlUtils.ResolveUrl(jQueryUiLocalFallbackUrl)),
                                            true, ScriptRenderModes.Header);
            }

            return;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Renders the scripts contained in this control
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            // Use ClientScript Proxy for all script injection except inline
            ClientScriptProxy scriptProxy = ClientScriptProxy.Current;

            writer.WriteLine(); // empty line

            foreach (ScriptItem script in InternalScripts)
            {
                // We only need to handle inline here - others have been handled in OnPreRender
                if (script.RenderMode != ScriptRenderModes.Inline)
                {
                    continue;
                }

                // Allow inheriting from control which is the default behavior
                if (script.RenderMode == ScriptRenderModes.Inherit)
                {
                    script.RenderMode = RenderMode;
                }

                // Fix up url to allow ~/ syntax
                string src = ResolveUrl(script.Src);

                if (script.AllowMinScript && !HttpContext.Current.IsDebuggingEnabled)
                {
                    src = src.ToLower().Replace(".js", MinScriptExtension);
                }

                writer.Write("<script src=\"" + src + "\" type=\"text/javascript\"></script>\r\n");
            }
        }
        /// <summary>
        /// This method just builds the various JavaScript blocks as strings
        /// and assigns them to the ClientScript object.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            if (!IsCallback)
            {
                ClientScriptProxy = ClientScriptProxy.Current;

                // If we're not in a callback provide script to client
                if (!string.IsNullOrEmpty(jQueryScriptLocation))
                {
                    ScriptLoader.LoadjQuery(this.Page);
                }
                //ClientScriptProxy.LoadControlScript(this, jQueryScriptLocation, ControlResources.JQUERY_SCRIPT_RESOURCE, ScriptRenderModes.HeaderTop);

                ClientScriptProxy.LoadControlScript(this, ScriptLocation, ControlResources.WWJQUERY_SCRIPT_RESOURCE, ScriptRenderModes.Header);

                // Generate the class wrapper and class loader function
                GenerateControlSpecificJavaScript();
            }
            else
            {
                if (PageProcessingMode == CallbackProcessingModes.PagePreRender)
                {
                    HandleCallback();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads the ww.jquery.js library from Resources at the end of the Html Header (if available)
        /// </summary>
        /// <param name="control"></param>
        /// <param name="loadjQuery"></param>
        public static void LoadwwjQuery(Control control, bool loadjQuery = true)
        {
            // jQuery is also required
            if (loadjQuery)
            {
                LoadjQuery(control);
            }

            ClientScriptProxy p = ClientScriptProxy.Current;

            p.RegisterClientScriptResource(control, typeof(ControlResources), ControlResources.WWJQUERY_SCRIPT_RESOURCE, ScriptRenderModes.Header);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Code that embeds related resources (.js and css)
        /// </summary>
        /// <param name="scriptProxy"></param>
        protected void RegisterResources(ClientScriptProxy scriptProxy)
        {
            // Use ScriptProxy to load jQuery and ww.Jquery
            ScriptLoader.LoadjQuery(this);
            ScriptLoader.LoadjQueryUi(this, null);

            // if a theme is provided embed a link to the stylesheet
            if (!string.IsNullOrEmpty(Theme))
            {
                string cssPath = this.CssBasePath.Replace("/base/", "/" + Theme + "/");
                scriptProxy.RegisterCssLink(Page, typeof(ControlResources), cssPath, cssPath);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handle writing out scripts to header or 'ASP.NET script body'
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // Use ClientScript Proxy for all script injection except inline
            scriptProxy = ClientScriptProxy.Current;

            // Now process all but inline scripts -
            // inline scripts must be rendered in Render()
            foreach (ScriptItem script in InternalScripts)
            {
                RegisterScriptItem(script);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Code that embeds related resources (.js and css)
        /// </summary>
        /// <param name="scriptProxy"></param>
        protected void RegisterResources(ClientScriptProxy scriptProxy)
        {
            scriptProxy.LoadControlScript(this, jQueryJs, ControlResources.JQUERY_SCRIPT_RESOURCE, ScriptRenderModes.HeaderTop);
            scriptProxy.RegisterClientScriptInclude(Page, typeof(ControlResources), CalendarJs, ScriptRenderModes.Header);

            string cssPath = CalendarCss;

            if (!string.IsNullOrEmpty(Theme))
            {
                cssPath = cssPath.Replace("/base/", "/" + Theme + "/");
            }

            scriptProxy.RegisterCssLink(Page, typeof(ControlResources), cssPath, cssPath);
        }
Exemplo n.º 10
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!DesignMode)
            {
                ScriptProxy = ClientScriptProxy.Current;

                // Use ScriptProxy to load jQuery and ww.Jquery
                if (!string.IsNullOrEmpty(jQueryScriptLocation))
                {
                    ScriptLoader.LoadjQuery(this);
                }

                ScriptProxy.LoadControlScript(this, ScriptLocation, ControlResources.WWJQUERY_SCRIPT_RESOURCE, ScriptRenderModes.Header);
            }
        }
Exemplo n.º 11
0
        protected override void OnPreRender(EventArgs e)
        {
            ClientScriptProxy = ClientScriptProxy.Current;

            if (Visible && !string.IsNullOrEmpty(Text) && DisplayTimeout > 0)
            {
                // Embed the client script library as Web Resource Link
                ScriptLoader.LoadjQuery(this);

                string Script =
                    @"setTimeout(function() { $('#" + ClientID + @"').fadeOut('slow') }," + DisplayTimeout.ToString() + ");";

                //@"window.setTimeout(""document.getElementById('" + ClientID + @"').style.display='none';""," + DisplayTimeout.ToString() + @");";

                ClientScriptProxy.RegisterStartupScript(this, typeof(ErrorDisplay), "DisplayTimeout", Script, true);
            }
            base.OnPreRender(e);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Read the HtmlGeneric Script controls and parse them into
        /// Internal scripts at page load time
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            // Save a Per Request instance in Page.Items so we can retrieve it
            // generically from code with wwScriptContainer.Current

            if (!Page.Items.Contains(STR_CONTEXTID))
            {
                Page.Items[STR_CONTEXTID] = this;
            }
            else
            {
                // ScriptContainer already exists elsewhere on the page - combine scripts
                ScriptContainer container = Page.Items[STR_CONTEXTID] as ScriptContainer;
                foreach (HtmlGenericControl scriptItem in container.Scripts)
                {
                    this.Scripts.Add(scriptItem);
                }
            }

            base.OnInit(e);

            scriptProxy = ClientScriptProxy.Current;

            // Pick up HtmlGeneric controls parse into Script objects
            // and add to Internal scripts for final processing
            foreach (HtmlGenericControl ctl in Scripts)
            {
                // Take generic control and parse into Script object
                ScriptItem script = ParseScriptProperties(ctl);
                if (script == null)
                {
                    continue;
                }

                // Insert into the list at the head of the list before 'manually'
                // added script entries
                //AddScript(script);

                // Register these items immediately at startup
                // script refs defined in doc take precendence over code added ones
                RegisterScriptItem(script);
            }
        }
Exemplo n.º 13
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            ClientScriptProxy proxy = ClientScriptProxy.Current;

            proxy.Require(CurrentSite, Require);

            foreach (string css in StringUtil.Split(Css, ",", true, true))
            {
                if (css.Contains("|"))
                {
                    string[] array = StringUtil.Split(css, "|", true, true);
                    if (array.Length != 2)
                    {
                        continue;
                    }

                    proxy.RegisterCssResource(array[1], array[0]);
                }
                else if (css.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (css.StartsWith("~"))
                    {
                        proxy.RegisterCss(ServerUtil.ResolveUrl(css));
                    }
                    else if (css.StartsWith("."))
                    {
                        proxy.RegisterCss(StringUtil.CombinUrl(CurrentSite.VirtualPath, CurrentSite.ThemeRoot, MobileDetect.Instance.GetRealThemeName(CurrentSite), css.Substring(1)));
                    }
                    else
                    {
                        proxy.RegisterCss(StringUtil.CombinUrl(CurrentSite.VirtualPath, css));
                    }
                }
                else
                {
                    proxy.RegisterCssResource(string.Format("Kiss.Web.jQuery.{0}.css", css));
                }
            }
        }
Exemplo n.º 14
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            JContext jc = JContext.Current;

            if (jc.User == null)
            {
                return;
            }

            isSiteAdmin = jc.User.HasPermission(string.Format("site.control_panel@{0}",
                                                              jc.Area["support_multi_site"].ToBoolean() ? jc.SiteId : string.Empty));

            jc.Context.Items["_has_controlpanel_permission_"] = isSiteAdmin;

            foreach (var cpItem in Plugin.Plugins.GetPlugins <ControlPanelItemAttribute>(JContext.Current.User))
            {
                Object obj = Activator.CreateInstance(cpItem.Decorates);
                if (obj is Control)
                {
                    Controls.Add(obj as Control);
                }

                renderers.Add(obj as IControlPanelItemRenderer);
            }

            if (renderers.Count == 0 || !isSiteAdmin)
            {
                return;
            }

            ClientScriptProxy proxy = ClientScriptProxy.Current;

            proxy.Require(jc.Area, "jquery.js,kiss.js,kiss.css");

            proxy.RegisterCssResource(GetType(),
                                      "Kiss.Web.jQuery.cp.c.css");
        }
Exemplo n.º 15
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     ClientScriptProxy = ClientScriptProxy.Current;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Read the HtmlGeneric Script controls and parse them into
        /// Internal scripts at page load time
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {

            // Save a Per Request instance in Page.Items so we can retrieve it
            // generically from code with wwScriptContainer.Current
            
            if (!Page.Items.Contains(STR_CONTEXTID))
                Page.Items[STR_CONTEXTID] = this;
            else
            {
                // ScriptContainer already exists elsewhere on the page - combine scripts
                ScriptContainer container = Page.Items[STR_CONTEXTID] as ScriptContainer;
                foreach(HtmlGenericControl scriptItem in container.Scripts)
                {
                    this.Scripts.Add(scriptItem);
                }
            }

            base.OnInit(e);

            scriptProxy = ClientScriptProxy.Current;

            // Pick up HtmlGeneric controls parse into Script objects
            // and add to Internal scripts for final processing
            foreach (HtmlGenericControl ctl in Scripts)
            {
                // Take generic control and parse into Script object
                ScriptItem script = ParseScriptProperties(ctl);
                if (script == null)
                    continue;

                // Insert into the list at the head of the list before 'manually'
                // added script entries
                //AddScript(script);

                // Register these items immediately at startup 
                // script refs defined in doc take precendence over code added ones
                RegisterScriptItem(script);
                
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Most of the work happens here for generating the hook up script code
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            // Ignore if we're calling this in a Callback
            if (AjaxMethodCallback.IsCallback)
            {
                return;
            }

            base.OnPreRender(e);

            // MS AJAX aware script management
            ClientScriptProxy scriptProxy = ClientScriptProxy.Current;

            // Register resources
            RegisterResources(scriptProxy);

            // Capture and map the various option parameters
            StringBuilder sbOptions = new StringBuilder(512);

            sbOptions.Append("{");


            if (!string.IsNullOrEmpty(OnClientSelection))
            {
                sbOptions.Append("select: " + OnClientSelection + ",");
            }
            else
            {
                sbOptions.AppendLine(
                    @"select: function (e, ui) {
                        $(""#" + this.UniqueID + @""").val(ui.item.value);
                    },");
            }


            if (CallbackHandler != null)
            {
                // point the service Url back to the current page method
                if (AjaxMethodCallback != null)
                {
                    ServerUrl = Page.Request.Url.LocalPath + "?" + "Method=AutoCompleteCallbackHandler&CallbackTarget=" + AjaxMethodCallback.ID;
                }
            }

            if (!string.IsNullOrEmpty(ServerUrl))
            {
                sbOptions.Append("source: \"" + ServerUrl + "\",");
            }

            sbOptions.AppendFormat("autoFocus: {0},delay: {1},minLength: {2},", AutoFocus.ToString().ToLower(), Delay, MinLength);

            // strip off trailing ,
            sbOptions.Length--;

            sbOptions.Append("}");

            // Write out initilization code for calendar
            StringBuilder sbStartupScript = new StringBuilder(400);

            sbStartupScript.AppendLine("$(document).ready( function() {");

            sbStartupScript.AppendFormat("      var autocompl = $(\"#{0}\").autocomplete({1});\r\n",
                                         ClientID, sbOptions.ToString());

            // close out the script function
            sbStartupScript.AppendLine("} );");

            scriptProxy.RegisterStartupScript(Page, typeof(ControlResources), "_cal" + UniqueID,
                                              sbStartupScript.ToString(), true);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Code that embeds related resources (.js and css)
        /// </summary>
        /// <param name="scriptProxy"></param>
        protected void RegisterResources(ClientScriptProxy scriptProxy)
        {
            // Use ScriptProxy to load jQuery and ww.Jquery
            ScriptLoader.LoadjQuery(this);
            ScriptLoader.LoadjQueryUi(this, null);

            // if a theme is provided embed a link to the stylesheet
            if (!string.IsNullOrEmpty(Theme))
            {

                string cssPath = this.CssBasePath.Replace("/base/", "/" + Theme + "/");
                scriptProxy.RegisterCssLink(Page, typeof(WebResources), cssPath, cssPath);
            }
        }
 /// <summary>
 /// This method just builds the various JavaScript blocks as strings
 /// and assigns them to the ClientScript object.
 /// </summary>
 /// <param name="e"></param>
 protected override void OnPreRender(EventArgs e)
 {
     if (!IsCallback)
     {
         ClientScriptProxy = ClientScriptProxy.Current;
         
         // If we're not in a callback provide script to client 
         if (!string.IsNullOrEmpty(jQueryScriptLocation))
             ScriptLoader.LoadjQuery(this.Page);
         
         ScriptLoader.LoadwwjQuery(this.Page, false);
         
         // Generate the class wrapper and class loader function
         GenerateControlSpecificJavaScript();
     }
     else
     {
         if (PageProcessingMode == CallbackProcessingModes.PagePreRender)
             HandleCallback();
     }
 }
Exemplo n.º 20
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            
            if (!DesignMode)
            {
                ScriptProxy = ClientScriptProxy.Current;

                // Use ScriptProxy to load jQuery and ww.Jquery
                if (!string.IsNullOrEmpty(jQueryScriptLocation))
                    ScriptLoader.LoadjQuery(this);

                ScriptLoader.LoadwwjQuery(this, false);                
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Handle writing out scripts to header or 'ASP.NET script body'
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // Use ClientScript Proxy for all script injection except inline
            scriptProxy = ClientScriptProxy.Current;

            // Now process all but inline scripts - 
            // inline scripts must be rendered in Render()
            foreach (ScriptItem script in InternalScripts)
            {
                RegisterScriptItem(script);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Most of the work happens here for generating the hook up script code
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // MS AJAX aware script management
            ClientScriptProxy scriptProxy = ClientScriptProxy.Current;

            // Register resources
            RegisterResources(scriptProxy);

            string dateFormat = DateFormat;

            if (string.IsNullOrEmpty(dateFormat) || dateFormat == "Auto")
            {
                // Try to create a data format string from culture settings
                // this code will fail if culture can't be mapped on server hence the empty try/catch
                try
                {
                    dateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
                }
                catch { }
            }

            dateFormat = dateFormat.ToLower().Replace("yyyy", "yy");

            // Capture and map the various option parameters
            StringBuilder sbOptions = new StringBuilder(512);

            sbOptions.Append("{");

            string onSelect = OnClientSelect;

            if (DisplayMode == DatePickerDisplayModes.Button)
            {
                sbOptions.Append("showOn: 'button',");
            }
            else if (DisplayMode == DatePickerDisplayModes.ImageButton)
            {
                string img = ButtonImage;
                if (img == "WebResource")
                {
                    img = scriptProxy.GetWebResourceUrl(this, typeof(ControlResources), ControlResources.CALENDAR_ICON_RESOURCE);
                }
                else
                {
                    img = ResolveUrl(ButtonImage);
                }

                sbOptions.Append("showOn: 'button', buttonImageOnly: true, buttonImage: '" + img + "',buttonText: 'Select date',");
            }
            else if (DisplayMode == DatePickerDisplayModes.Inline)
            {
                // need to store selection in the page somehow for inline since it's
                // not tied to a textbox
                scriptProxy.RegisterHiddenField(this, ClientID, Text);
                onSelect = ClientID + "OnSelect";
            }

            if (!string.IsNullOrEmpty(onSelect))
            {
                sbOptions.Append("onSelect: " + onSelect + ",");
            }

            if (DisplayMode != DatePickerDisplayModes.Inline)
            {
                if (!string.IsNullOrEmpty(OnClientBeforeShow))
                {
                    sbOptions.Append("beforeShow: function(y,z) { $('#ui-datepicker-div').maxZIndex(); " +
                                     OnClientBeforeShow + "(y,z); },");
                }
                else
                {
                    sbOptions.Append("beforeShow: function() { $('#ui-datepicker-div').maxZIndex(); },");
                }
            }

            if (MaxDate.HasValue)
            {
                sbOptions.Append("maxDate: " + UrlUtils.EncodeJsDate(MaxDate.Value) + ",");
            }

            if (MinDate.HasValue)
            {
                sbOptions.Append("minDate: " + UrlUtils.EncodeJsDate(MinDate.Value) + ",");
            }

            if (ShowButtonPanel)
            {
                sbOptions.Append("showButtonPanel: true,");
            }

            sbOptions.Append("dateFormat: '" + dateFormat + "'}");


            // Write out initilization code for calendar
            StringBuilder sbStartupScript = new StringBuilder(400);

            sbStartupScript.AppendLine("$( function() {");


            if (DisplayMode != DatePickerDisplayModes.Inline)
            {
                scriptProxy.RegisterClientScriptBlock(Page,
                                                      typeof(ControlResources),
                                                      "__attachDatePickerInputKeys",
                                                      AttachDatePickerKeysScript, true);

                sbStartupScript.AppendFormat("var cal = jQuery('#{0}').datepicker({1}).attachDatepickerInputKeys();\r\n",
                                             ClientID, sbOptions);
            }
            else
            {
                sbStartupScript.AppendLine("var cal = jQuery('#" + ClientID + "Div').datepicker(" + sbOptions.ToString() + ")");

                if (SelectedDate.HasValue && SelectedDate.Value > new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc))
                {
                    CustomJsonSerializer ser = new CustomJsonSerializer();
                    ser.DateSerializationMode = JsonDateEncodingModes.NewDateExpression;
                    string jsDate = ser.Serialize(SelectedDate);

                    sbStartupScript.AppendLine("cal.datepicker('setDate'," + jsDate + ");");
                }
                else
                {
                    sbStartupScript.AppendLine("cal.datepicker('setDate',new Date());");
                }

                // Assign value to hidden form var on selection
                scriptProxy.RegisterStartupScript(this, typeof(ControlResources), UniqueID + "OnSelect",
                                                  "function  " + ClientID + "OnSelect(dateStr) {\r\n" +
                                                  ((!string.IsNullOrEmpty(OnClientSelect)) ? OnClientSelect + "(dateStr);\r\n" : "") +
                                                  "jQuery('#" + ClientID + "')[0].value = dateStr;\r\n}\r\n", true);
            }

            sbStartupScript.AppendLine("} );");
            scriptProxy.RegisterStartupScript(Page, typeof(ControlResources), "_cal" + UniqueID,
                                              sbStartupScript.ToString(), true);
        }
Exemplo n.º 23
0
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);

            if (StringUtil.IsNullOrEmpty(Js))
            {
                return;
            }

            ClientScriptProxy proxy = ClientScriptProxy.Current;

            foreach (string js in StringUtil.Split(Js, ",", true, true))
            {
                if (js.Contains("|"))
                {
                    string[] array = StringUtil.Split(js, "|", true, true);
                    if (array.Length != 2)
                    {
                        continue;
                    }

                    proxy.RegisterJsResource(array[1], array[0]);
                }
                else if (js.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (js.Contains("*"))
                    {
                        string vp    = "/";
                        var    index = js.LastIndexOf('/');
                        if (index != -1)
                        {
                            vp = js.Substring(0, index + 1);
                        }

                        string path;
                        if (vp.StartsWith("."))
                        {
                            path = ServerUtil.MapPath(StringUtil.CombinUrl(CurrentSite.VirtualPath, CurrentSite.ThemeRoot, MobileDetect.Instance.GetRealThemeName(CurrentSite), vp.Substring(1)));
                        }
                        else
                        {
                            path = ServerUtil.MapPath(StringUtil.CombinUrl(CurrentSite.VirtualPath, vp));
                        }

                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            continue;
                        }

                        foreach (var item in Directory.GetFiles(Path.GetDirectoryName(path), js.Substring(index + 1), SearchOption.AllDirectories))
                        {
                            string relativePath = item.ToLower().Replace(path.ToLower(), string.Empty);
                            relativePath = relativePath.Replace(Path.DirectorySeparatorChar, '/');

                            if (vp.StartsWith("~"))
                            {
                                proxy.RegisterJs(StringUtil.CombinUrl(ServerUtil.ResolveUrl(vp), relativePath), NoCombine);
                            }
                            else if (vp.StartsWith("."))
                            {
                                proxy.RegisterJs(StringUtil.CombinUrl(CurrentSite.VirtualPath,
                                                                      CurrentSite.ThemeRoot,
                                                                      MobileDetect.Instance.GetRealThemeName(CurrentSite),
                                                                      vp.Substring(1),
                                                                      relativePath), NoCombine);
                            }
                            else
                            {
                                proxy.RegisterJs(StringUtil.CombinUrl(CurrentSite.VirtualPath, StringUtil.CombinUrl(vp, relativePath)), NoCombine);
                            }
                        }
                    }
                    else
                    {
                        if (js.StartsWith("~"))
                        {
                            proxy.RegisterJs(ServerUtil.ResolveUrl(js), NoCombine);
                        }
                        else if (js.StartsWith("."))
                        {
                            proxy.RegisterJs(StringUtil.CombinUrl(CurrentSite.VirtualPath, CurrentSite.ThemeRoot, MobileDetect.Instance.GetRealThemeName(CurrentSite), js.Substring(1)), NoCombine);
                        }
                        else
                        {
                            proxy.RegisterJs(StringUtil.CombinUrl(CurrentSite.VirtualPath, js), NoCombine);
                        }
                    }
                }
                else
                {
                    proxy.RegisterJsResource(
                        GetType(),
                        string.Format("Kiss.Web.jQuery.{0}.js", js), NoCombine);
                }
            }
        }
Exemplo n.º 24
0
        protected override void OnPreRender(EventArgs e)
        {
            ClientScriptProxy = ClientScriptProxy.Current;

            if (Visible && !string.IsNullOrEmpty(Text) && DisplayTimeout > 0)
            {
                // Embed the client script library as Web Resource Link
                ScriptLoader.LoadjQuery(this);

                string Script =
                    @"setTimeout(function() { $('#" + ClientID + @"').fadeOut('slow') }," + DisplayTimeout.ToString() + ");";

                //@"window.setTimeout(""document.getElementById('" + ClientID + @"').style.display='none';""," + DisplayTimeout.ToString() + @");";

                ClientScriptProxy.RegisterStartupScript(this, typeof(ErrorDisplay), "DisplayTimeout", Script, true);
            }
            base.OnPreRender(e);
        }
Exemplo n.º 25
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     ClientScriptProxy = ClientScriptProxy.Current;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Code that embeds related resources (.js and css)
        /// </summary>
        /// <param name="scriptProxy"></param>
        protected void RegisterResources(ClientScriptProxy scriptProxy)
        {
            scriptProxy.LoadControlScript(this, jQueryJs, WebResources.JQUERY_SCRIPT_RESOURCE, ScriptRenderModes.HeaderTop);
            scriptProxy.RegisterClientScriptInclude(Page, typeof(WebResources), CalendarJs, ScriptRenderModes.Header);

            string cssPath = CalendarCss;
            if (!string.IsNullOrEmpty(Theme))
                cssPath = cssPath.Replace("/base/", "/" + Theme + "/");

            scriptProxy.RegisterCssLink(Page, typeof(WebResources), cssPath, cssPath);
        }