2013-11-28 14:27:58 +11:00
|
|
|
using System.Web;
|
|
|
|
|
using ClientDependency.Core;
|
2013-11-28 10:37:08 +11:00
|
|
|
using Newtonsoft.Json.Linq;
|
2013-11-07 17:16:22 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
using Umbraco.Core.Manifest;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.UI.JavaScript
|
|
|
|
|
{
|
2013-11-28 10:37:08 +11:00
|
|
|
internal class CssInitialization : AssetInitialization
|
2013-11-07 17:16:22 +01:00
|
|
|
{
|
|
|
|
|
private readonly ManifestParser _parser;
|
|
|
|
|
public CssInitialization(ManifestParser parser)
|
|
|
|
|
{
|
|
|
|
|
_parser = parser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processes all found manifest files and outputs yepnope.injectcss calls for all css files found in all manifests
|
|
|
|
|
/// </summary>
|
2013-11-28 14:27:58 +11:00
|
|
|
public string GetStylesheetInitialization(HttpContextBase httpContext)
|
2014-01-15 17:18:23 +11:00
|
|
|
{
|
|
|
|
|
var result = GetStylesheetInitializationArray(httpContext);
|
|
|
|
|
|
|
|
|
|
return ParseMain(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JArray GetStylesheetInitializationArray(HttpContextBase httpContext)
|
2013-11-07 17:16:22 +01:00
|
|
|
{
|
|
|
|
|
var merged = new JArray();
|
|
|
|
|
foreach (var m in _parser.GetManifests())
|
|
|
|
|
{
|
|
|
|
|
ManifestParser.MergeJArrays(merged, m.StylesheetInitialize);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-28 10:37:08 +11:00
|
|
|
//now we can optimize if in release mode
|
2015-03-18 19:06:41 +11:00
|
|
|
merged = OptimizeAssetCollection(merged, ClientDependencyType.Css, httpContext);
|
2013-11-28 14:27:58 +11:00
|
|
|
|
|
|
|
|
//now we need to merge in any found cdf declarations on property editors
|
|
|
|
|
ManifestParser.MergeJArrays(merged, ScanPropertyEditors(ClientDependencyType.Css, httpContext));
|
2013-11-28 10:37:08 +11:00
|
|
|
|
2014-01-15 17:18:23 +11:00
|
|
|
return merged;
|
2013-11-07 17:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses the CssResources.Main and returns a yepnop.injectCss format
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="files"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
internal static string ParseMain(JArray files)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
foreach (var file in files)
|
2014-04-29 11:38:13 +02:00
|
|
|
sb.AppendFormat("{0}LazyLoad.css('{1}');", Environment.NewLine, file);
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|