using System;
using System.Collections.Generic;
using System.Text;
namespace umbraco.presentation.ClientDependency
{
///
/// This attribute is used for data types that uses client assets like Javascript and CSS for liveediting.
/// The Live Editing feature in umbraco will look for this attribute and preload all dependencies to the page
/// to ensure that all client events and assets gets loaded
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class ClientDependencyAttribute : Attribute, IClientDependencyFile
{
public ClientDependencyAttribute()
{
Priority = DefaultPriority;
DoNotOptimize = false;
}
///
/// If a priority is not set, the default will be 100.
///
///
/// 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.
///
protected const int DefaultPriority = 100;
///
/// If set to true, this file will not be compressed, combined, etc...
/// it will be rendered out as is.
///
///
/// Useful for debugging dodgy scripts.
/// Default is false.
///
public bool DoNotOptimize { get; set; }
///
/// If dependencies have a composite group name specified, the system will combine all dependency
/// file contents under the one group name and GZIP the output to output cache.
///
///
/// This is optional but should be used to decrease the number of requests, save bandwidth and increase
/// performance on the client side.
/// Though both javascript and css files may have the same group name specified, they will be treated seperately.
///
//public string CompositeGroupName { get; set; }
///
/// Gets or sets the priority.
///
/// The priority.
public int Priority { get; set; }
///
/// Gets or sets the file path.
///
/// The file path.
public string FilePath { get; set; }
///
/// The path alias to be pre-pended to the file path if specified.
/// The alias is specified in in the ClientDependencyHelper constructor.
/// If the alias specified does not exist in the ClientDependencyHelper
/// path collection, an exception is thrown.
///
public string PathNameAlias { get; set; }
///
/// Gets or sets the type of the dependency.
///
/// The type of the dependency.
public ClientDependencyType DependencyType { get; set; }
///
/// Gets or sets the name of an optional javascript method that should be called on load.
///
/// The name of the method.
public string InvokeJavascriptMethodOnLoad { get; set; }
public ClientDependencyAttribute(ClientDependencyType dependencyType, string fullFilePath)
: this(DefaultPriority, dependencyType, fullFilePath, string.Empty, string.Empty)
{ }
public ClientDependencyAttribute(ClientDependencyType dependencyType, string fileName, string pathNameAlias)
: this(DefaultPriority, dependencyType, fileName, pathNameAlias, string.Empty)
{ }
///
/// Initializes a new instance of the class.
///
/// The priority.
/// Type of the dependency.
/// The file path to the dependency.
public ClientDependencyAttribute(int priority, ClientDependencyType dependencyType, string fullFilePath)
: this(priority, dependencyType, fullFilePath, string.Empty, string.Empty)
{ }
///
/// Initializes a new instance of the class.
///
/// The priority.
/// Type of the dependency.
/// The file path to the dependency.
///
/// If set, this will prepend the 'Path' found in the ClientDependencyPathCollection with the pathName specified.
/// If the pathName specified is not found in the collection, an exception will be thrown.
///
public ClientDependencyAttribute(int priority, ClientDependencyType dependencyType, string fileName, string pathNameAlias)
: this(priority, dependencyType, fileName, pathNameAlias, string.Empty)
{ }
///
/// Initializes a new instance of the class.
///
/// The priority.
/// Type of the dependency.
/// The file path to the dependency.
/// if set to true the current umbraco path will be prefixed to the filePath.
/// The name of the Javascript method to invoke when the dependency is loaded.
public ClientDependencyAttribute(int priority, ClientDependencyType dependencyType, string fileName, string pathNameAlias, string invokeJavascriptMethodOnLoad)
{
if (String.IsNullOrEmpty(fileName))
throw new ArgumentNullException("fileName");
Priority = priority;
FilePath = fileName;
PathNameAlias = pathNameAlias;
//CompositeGroupName = compositeGroupName;
DependencyType = dependencyType;
InvokeJavascriptMethodOnLoad = invokeJavascriptMethodOnLoad ?? string.Empty;
}
}
}