/// <summary> /// Load all script references needed by toolkits registered at config file based on bundles. /// If bundles is null then all control types from config are loaded. /// </summary> /// <param name="context">Current HttpContext</param> /// <param name="bundles">Name of bundles</param> /// <returns>List of script reference</returns> public List <ScriptReference> LoadScriptReferences(HttpContextBase context, string[] bundles) { _scriptReferences = new List <ScriptReference>(); foreach (var control in _scriptManagerConfig.GetControlTypesInBundles(context, bundles)) { var scriptRefs = ScriptObjectBuilder.GetScriptReferences(control); foreach (var scriptRef in scriptRefs) { if (_scriptReferences.All(s => s.Name != scriptRef.Name)) { _scriptReferences.Add(scriptRef); } } } _scriptEntriesLoaded = true; return(_scriptReferences); }
protected virtual IEnumerable <ScriptDescriptor> GetScriptDescriptors() { if (Visible) { List <ScriptDescriptor> descriptors = new List <ScriptDescriptor>(); ScriptControlDescriptor descriptor = new ScriptControlDescriptor(ClientControlType, ClientID); ScriptObjectBuilder.DescribeComponent(this, descriptor, this, this); descriptor.AddElementProperty("textBoxControl", TextBoxControl.ClientID); descriptor.AddElementProperty("buttonControl", ButtonControl.ClientID); descriptor.AddElementProperty("hiddenFieldControl", HiddenFieldControl.ClientID); descriptor.AddElementProperty("optionListControl", OptionListControl.ClientID); descriptor.AddElementProperty("comboTableControl", ComboTable.ClientID); //descriptor.AddProperty("selectedIndex", SelectedIndex); descriptor.AddProperty("autoCompleteMode", AutoCompleteMode); descriptor.AddProperty("dropDownStyle", DropDownStyle); descriptors.Add(descriptor); return(descriptors); } return(null); }
public List <ScriptReference> GetScriptReferences(HttpContextBase context, string[] bundles, out ScriptReference[] addedScriptReferences, out ScriptReference[] removedScriptReferences) { var scriptReferences = new List <ScriptReference>(); foreach ( var control in GetControlTypesInBundles(context, bundles, out addedScriptReferences, out removedScriptReferences)) { var scriptRefs = ScriptObjectBuilder.GetScriptReferences(control).ToList(); foreach (var scriptRef in scriptRefs) { if (scriptReferences.All(s => s.Name != scriptRef.Name)) { scriptReferences.Add(scriptRef); } } } scriptReferences = scriptReferences.Distinct().ToList(); if (addedScriptReferences != null) { foreach (var script in addedScriptReferences) { scriptReferences.Add(script); } } if (removedScriptReferences != null) { foreach (var script in removedScriptReferences) { var scriptToRemove = scriptReferences.FirstOrDefault(s => s.Name.Equals(script.Name) && s.Assembly.Equals(script.Assembly)); if (scriptToRemove != null) { scriptReferences.Remove(scriptToRemove); } } } return(scriptReferences); }
/// <summary> /// Handles OnLoad /// </summary> /// <param name="e">event args</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); ScriptObjectBuilder.RegisterCssReferences(this); }
// Token: 0x060000E4 RID: 228 RVA: 0x00003917 File Offset: 0x00001B17 public static IEnumerable <string> GetCssReferences(Control control) { return(ScriptObjectBuilder.GetCssReferences(control, control.GetType(), new Stack <Type>())); }
// Token: 0x060000E3 RID: 227 RVA: 0x000038E4 File Offset: 0x00001AE4 public static IEnumerable <ScriptReference> GetScriptReferences(Type type, bool ignoreStartingTypeReferences) { List <ScriptObjectBuilder.ResourceEntry> scriptReferencesInternal = ScriptObjectBuilder.GetScriptReferencesInternal((ignoreStartingTypeReferences && null != type) ? type.BaseType : type, new Stack <Type>()); return(ScriptObjectBuilder.ScriptReferencesFromResourceEntries(scriptReferencesInternal)); }
// Token: 0x060000E9 RID: 233 RVA: 0x00003EC8 File Offset: 0x000020C8 private static IEnumerable <string> GetCssReferences(Control control, Type type, Stack <Type> typeReferenceStack) { if (typeReferenceStack.Contains(type)) { throw new InvalidOperationException("Circular reference detected."); } IList <string> list; if (ScriptObjectBuilder.cssCache.TryGetValue(type, out list)) { return(list); } typeReferenceStack.Push(type); IEnumerable <string> result; try { lock (ScriptObjectBuilder.sync) { if (ScriptObjectBuilder.cssCache.TryGetValue(type, out list)) { result = list; } else { List <string> list2 = new List <string>(); List <RequiredScriptAttribute> list3 = new List <RequiredScriptAttribute>(); foreach (RequiredScriptAttribute item in type.GetCustomAttributes(typeof(RequiredScriptAttribute), true)) { list3.Add(item); } list3.Sort((RequiredScriptAttribute left, RequiredScriptAttribute right) => left.LoadOrder.CompareTo(right.LoadOrder)); foreach (RequiredScriptAttribute requiredScriptAttribute in list3) { if (requiredScriptAttribute.ExtenderType != null) { list2.AddRange(ScriptObjectBuilder.GetCssReferences(control, requiredScriptAttribute.ExtenderType, typeReferenceStack)); } } List <ScriptObjectBuilder.ResourceEntry> list4 = new List <ScriptObjectBuilder.ResourceEntry>(); int num = 0; Type type2 = type; while (type2 != null && type2 != typeof(object)) { object[] customAttributes2 = Attribute.GetCustomAttributes(type2, typeof(ClientCssResourceAttribute), false); num -= customAttributes2.Length; foreach (ClientCssResourceAttribute clientCssResourceAttribute in customAttributes2) { list4.Add(new ScriptObjectBuilder.ResourceEntry(clientCssResourceAttribute.ResourcePath, type2, num + clientCssResourceAttribute.LoadOrder)); } type2 = type2.BaseType; } list4.Sort((ScriptObjectBuilder.ResourceEntry l, ScriptObjectBuilder.ResourceEntry r) => l.Order.CompareTo(r.Order)); foreach (ScriptObjectBuilder.ResourceEntry resourceEntry in list4) { list2.Add(control.Page.ClientScript.GetWebResourceUrl(resourceEntry.ComponentType, resourceEntry.ResourcePath)); } Dictionary <string, object> dictionary = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase); List <string> list5 = new List <string>(); foreach (string text in list2) { if (!dictionary.ContainsKey(text)) { dictionary.Add(text, null); list5.Add(text); } } list = new ReadOnlyCollection <string>(list5); ScriptObjectBuilder.cssCache.Add(type, list); result = list; } } } finally { typeReferenceStack.Pop(); } return(result); }
// Token: 0x060000E2 RID: 226 RVA: 0x000038D8 File Offset: 0x00001AD8 public static IEnumerable <ScriptReference> GetScriptReferences(Type type) { return(ScriptObjectBuilder.GetScriptReferences(type, false)); }
// Token: 0x060000E8 RID: 232 RVA: 0x00003C2C File Offset: 0x00001E2C private static List <ScriptObjectBuilder.ResourceEntry> GetScriptReferencesInternal(Type type, Stack <Type> typeReferenceStack) { if (typeReferenceStack.Contains(type)) { throw new InvalidOperationException("Circular reference detected."); } List <ScriptObjectBuilder.ResourceEntry> list; if (ScriptObjectBuilder.cache.TryGetValue(type, out list)) { return(list); } typeReferenceStack.Push(type); List <ScriptObjectBuilder.ResourceEntry> result; try { lock (ScriptObjectBuilder.sync) { if (!ScriptObjectBuilder.cache.TryGetValue(type, out list)) { list = new List <ScriptObjectBuilder.ResourceEntry>(); List <RequiredScriptAttribute> list2 = new List <RequiredScriptAttribute>(); foreach (RequiredScriptAttribute item in type.GetCustomAttributes(typeof(RequiredScriptAttribute), true)) { list2.Add(item); } list2.Sort((RequiredScriptAttribute left, RequiredScriptAttribute right) => left.LoadOrder.CompareTo(right.LoadOrder)); foreach (RequiredScriptAttribute requiredScriptAttribute in list2) { if (requiredScriptAttribute.ExtenderType != null) { list.AddRange(ScriptObjectBuilder.GetScriptReferencesInternal(requiredScriptAttribute.ExtenderType, typeReferenceStack)); } } int num = 0; List <ScriptObjectBuilder.ResourceEntry> list3 = new List <ScriptObjectBuilder.ResourceEntry>(); Type type2 = type; while (type2 != null && type2 != typeof(object)) { object[] customAttributes2 = Attribute.GetCustomAttributes(type2, typeof(ClientScriptResourceAttribute), false); num -= customAttributes2.Length; foreach (ClientScriptResourceAttribute clientScriptResourceAttribute in customAttributes2) { ScriptObjectBuilder.ResourceEntry item2 = new ScriptObjectBuilder.ResourceEntry(clientScriptResourceAttribute.ResourcePath, type2, num + clientScriptResourceAttribute.LoadOrder); if (!list.Contains(item2) && !list3.Contains(item2)) { list3.Add(item2); } } type2 = type2.BaseType; } list3.Sort((ScriptObjectBuilder.ResourceEntry l, ScriptObjectBuilder.ResourceEntry r) => l.Order.CompareTo(r.Order)); list.AddRange(list3); ScriptObjectBuilder.cache.Add(type, list); } result = list; } } finally { typeReferenceStack.Pop(); } return(result); }
/// <summary> /// Register's the Css references for this control /// </summary> /// <param name="control"></param> public static void RegisterCssReferences(Control control) { // Add the link to the page header instead of inside the body which is not xhtml compliant HtmlHead header = control.Page.Header; foreach (string styleSheet in ScriptObjectBuilder.GetCssReferences(control)) { if (null == header) { // It would be nice to add the required header here, but it's too late in the page // lifecycle to be modifying the Page.Controls collection - throw an informative // exception instead and let the page author make the simple change. throw new NotSupportedException("This page is missing a HtmlHead control which is required for the CSS stylesheet link that is being added. Please add <head runat=\"server\" />."); } bool addIt = true; // looking for this stylesheet already in the header foreach (Control c in header.Controls) { HtmlLink l = c as HtmlLink; if (null != l && styleSheet.Equals(l.Href, StringComparison.OrdinalIgnoreCase)) { addIt = false; break; } } if (addIt) { HtmlLink link = new HtmlLink(); link.Href = styleSheet; link.Attributes.Add("type", "text/css"); link.Attributes.Add("rel", "stylesheet"); header.Controls.Add(link); // ASP.NET AJAX doesn't currently send a new head element down during an async postback, // so we do the same thing on the client by registering the appropriate script for after // the update. ScriptManager scriptManager = ScriptManager.GetCurrent(control.Page); if (null == scriptManager) { throw new InvalidOperationException(Resources.E_NoScriptManager); } if (scriptManager.IsInAsyncPostBack) { ScriptManager.RegisterClientScriptBlock(control, control.GetType(), "RegisterCssReferences", "if (window.__AjaxControlToolkitControlCssLoaded == null || typeof window.__AjaxControlToolkitControlCssLoaded == 'undefined') {" + " window.__AjaxControlToolkitControlCssLoaded = new Array();" + "}" + "var controlCssLoaded = window.__AjaxControlToolkitControlCssLoaded; " + "var head = document.getElementsByTagName('HEAD')[0];" + "if (head && !Array.contains(controlCssLoaded,'" + styleSheet + "')) {" + "var linkElement = document.createElement('link');" + "linkElement.type = 'text/css';" + "linkElement.rel = 'stylesheet';" + "linkElement.href = '" + styleSheet + "';" + "head.appendChild(linkElement);" + "controlCssLoaded.push('" + styleSheet + "');" + "}" , true); } } } }