DO NOT DOWNLOAD. DOWNLOAD LATEST STABLE FROM RELEASE TAB

Resolves 23626. ClientDependency work.

[TFS Changeset #57219]
This commit is contained in:
Shandem
2009-07-26 15:13:15 +00:00
parent 9e9598cbb5
commit 9a46338123
72 changed files with 830 additions and 326 deletions

View File

@@ -12,6 +12,17 @@ namespace umbraco.presentation.ClientDependency.Controls
{
Priority = DefaultPriority;
DoNotOptimize = false;
PathNameAlias = "";
}
public ClientDependencyInclude(IClientDependencyFile file)
{
Priority = file.Priority;
DoNotOptimize = file.DoNotOptimize;
PathNameAlias = file.PathNameAlias;
FilePath = file.FilePath;
DependencyType = file.DependencyType;
InvokeJavascriptMethodOnLoad = file.InvokeJavascriptMethodOnLoad;
}
/// <summary>
@@ -21,7 +32,7 @@ namespace umbraco.presentation.ClientDependency.Controls
/// This will generally mean that if a developer doesn't specify a priority it will come after all other dependencies that
/// have unless the priority is explicitly set above 100.
/// </remarks>
protected const int DefaultPriority = 100;
public const int DefaultPriority = 100;
/// <summary>
/// If set to true, this file will not be compressed, combined, etc...
@@ -37,7 +48,6 @@ namespace umbraco.presentation.ClientDependency.Controls
public string FilePath { get; set; }
public string PathNameAlias { get; set; }
public string CompositeGroupName { get; set; }
public int Priority { get; set; }
public string InvokeJavascriptMethodOnLoad { get; set; }

View File

@@ -21,16 +21,66 @@ namespace umbraco.presentation.ClientDependency.Controls
IsDebugMode = false;
}
private const string ContextKey = "ClientDependencyLoader";
public static void RegisterDependency(string filePath, ClientDependencyType type)
{
RegisterDependency(filePath, "", type);
}
public static void RegisterDependency(string filePath, string pathNameAlias, ClientDependencyType type)
{
RegisterDependency(ClientDependencyInclude.DefaultPriority, false, filePath, pathNameAlias, type, "");
}
/// <summary>
/// Dynamically registers a dependency into the loader at runtime.
/// This is similar to ScriptManager.RegisterClientScriptInclude
/// </summary>
/// <param name="file"></param>
public static void RegisterDependency(int priority, bool doNotOptimize, string filePath, string pathNameAlias, ClientDependencyType type, string invokeJavascriptMethodOnLoad)
{
if (!HttpContext.Current.Items.Contains(ContextKey))
throw new NullReferenceException("No ClientDependencyLoader found in the current request");
ClientDependencyLoader loader = HttpContext.Current.Items[ContextKey] as ClientDependencyLoader;
if (loader == null)
throw new Exception("Could not find a ClientDependencyLoader in the current request");
//loader.RegisteredFiles.Add(file);
//create/add a new control to this control's collection
if (type == ClientDependencyType.Css)
{
CssInclude cssInc = new CssInclude();
cssInc.DoNotOptimize = doNotOptimize;
cssInc.Priority = priority;
cssInc.FilePath = filePath;
cssInc.PathNameAlias = pathNameAlias;
cssInc.InvokeJavascriptMethodOnLoad = invokeJavascriptMethodOnLoad;
loader.Controls.Add(cssInc);
}
else
{
JsInclude jsInc = new JsInclude();
jsInc.DoNotOptimize = doNotOptimize;
jsInc.Priority = priority;
jsInc.FilePath = filePath;
jsInc.PathNameAlias = pathNameAlias;
jsInc.InvokeJavascriptMethodOnLoad = invokeJavascriptMethodOnLoad;
loader.Controls.Add(jsInc);
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (HttpContext.Current.Items.Contains("ClientDependencyLoader"))
if (HttpContext.Current.Items.Contains(ContextKey))
{
throw new Exception("Only one ClientDependencyLoader may exist on a page");
}
else
{
HttpContext.Current.Items.Add("ClientDependencyLoader", true);
HttpContext.Current.Items.Add(ContextKey, this);
}
}

View File

@@ -12,5 +12,10 @@ namespace umbraco.presentation.ClientDependency.Controls
{
DependencyType = ClientDependencyType.Css;
}
public CssInclude(IClientDependencyFile file)
: base(file)
{
DependencyType = ClientDependencyType.Css;
}
}
}

View File

@@ -12,6 +12,11 @@ namespace umbraco.presentation.ClientDependency.Controls
{
DependencyType = ClientDependencyType.Javascript;
}
public JsInclude(IClientDependencyFile file)
: base(file)
{
DependencyType = ClientDependencyType.Javascript;
}
}
}