Enables the manifest to load custom stylesheets outside the js loading
This commit is contained in:
@@ -128,7 +128,14 @@ namespace Umbraco.Core.Manifest
|
||||
{
|
||||
throw new FormatException("The manifest is not formatted correctly contains more than one 'javascript' element");
|
||||
}
|
||||
|
||||
|
||||
//validate the css
|
||||
var cssinit = deserialized.Properties().Where(x => x.Name == "stylesheet").ToArray();
|
||||
if (cssinit.Length > 1)
|
||||
{
|
||||
throw new FormatException("The manifest is not formatted correctly contains more than one 'stylesheet' element");
|
||||
}
|
||||
|
||||
//validate the property editors section
|
||||
var propEditors = deserialized.Properties().Where(x => x.Name == "propertyEditors").ToArray();
|
||||
if (propEditors.Length > 1)
|
||||
@@ -139,6 +146,9 @@ namespace Umbraco.Core.Manifest
|
||||
var jConfig = init.Any() ? (JArray)deserialized["javascript"] : new JArray();
|
||||
ReplaceVirtualPaths(jConfig);
|
||||
|
||||
var cssConfig = cssinit.Any() ? (JArray)deserialized["stylesheet"] : new JArray();
|
||||
ReplaceVirtualPaths(cssConfig);
|
||||
|
||||
//replace virtual paths for each property editor
|
||||
if (deserialized["propertyEditors"] != null)
|
||||
{
|
||||
@@ -158,6 +168,7 @@ namespace Umbraco.Core.Manifest
|
||||
var manifest = new PackageManifest()
|
||||
{
|
||||
JavaScriptInitialize = jConfig,
|
||||
StyleSheetInitialize = cssConfig,
|
||||
PropertyEditors = propEditors.Any() ? (JArray)deserialized["propertyEditors"] : new JArray(),
|
||||
ParameterEditors = propEditors.Any() ? (JArray)deserialized["parameterEditors"] : new JArray()
|
||||
};
|
||||
|
||||
@@ -12,6 +12,11 @@ namespace Umbraco.Core.Manifest
|
||||
/// </summary>
|
||||
public JArray JavaScriptInitialize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The json array used to initialize the application with the CSS dependencies required
|
||||
/// </summary>
|
||||
public JArray StyleSheetInitialize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The json array of property editors
|
||||
/// </summary>
|
||||
|
||||
@@ -34,8 +34,13 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
var plugins = new DirectoryInfo(Server.MapPath("~/App_Plugins"));
|
||||
var parser = new ManifestParser(plugins);
|
||||
var requireJs = new JsInitialization(parser);
|
||||
var result = requireJs.GetJavascriptInitialization(JsInitialization.GetDefaultInitialization());
|
||||
var initJs = new JsInitialization(parser);
|
||||
var initCss = new CssInitialization(parser);
|
||||
|
||||
|
||||
var result = initJs.GetJavascriptInitialization(JsInitialization.GetDefaultInitialization());
|
||||
result += initCss.GetStylesheetInitialization();
|
||||
|
||||
return JavaScript(result);
|
||||
}
|
||||
|
||||
|
||||
51
src/Umbraco.Web/UI/JavaScript/CssInitialization.cs
Normal file
51
src/Umbraco.Web/UI/JavaScript/CssInitialization.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
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
|
||||
{
|
||||
internal class CssInitialization
|
||||
{
|
||||
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>
|
||||
public string GetStylesheetInitialization()
|
||||
{
|
||||
JArray merged = new JArray();
|
||||
foreach (var m in _parser.GetManifests())
|
||||
{
|
||||
ManifestParser.MergeJArrays(merged, m.StyleSheetInitialize);
|
||||
}
|
||||
|
||||
return ParseMain(merged);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Parses the CssResources.Main and returns a yepnop.injectCss format
|
||||
/// </summary>
|
||||
/// <param name="replacements"></param>
|
||||
/// <returns></returns>
|
||||
internal static string ParseMain(JArray files)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var file in files)
|
||||
sb.AppendFormat("{0}yepnope.injectCss('{1}');", Environment.NewLine, file);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,8 @@
|
||||
*/
|
||||
|
||||
/* temporary sorter lib, should be updated
|
||||
'lib/angular/angular-ui-sortable.js',*/
|
||||
'lib/jquery/jquery.sortable/jquery.sortable.js',
|
||||
'lib/angular/angular-ui-sortable.js',
|
||||
'lib/jquery/jquery.sortable/jquery.sortable.js',*/
|
||||
|
||||
/* App-wide file-upload helper */
|
||||
'lib/jquery/jquery.upload/js/jquery.fileupload.js',
|
||||
|
||||
@@ -373,6 +373,7 @@
|
||||
<Compile Include="Trees\DataTypeTreeController.cs" />
|
||||
<Compile Include="Trees\MemberTreeController.cs" />
|
||||
<Compile Include="Trees\Menu\CreateChildEntity.cs" />
|
||||
<Compile Include="UI\JavaScript\CssInitialization.cs" />
|
||||
<Compile Include="umbraco.presentation\umbraco\create.aspx.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user