mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Changing the way we check for files for TinyMCE - should increase performance of loading the editor
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard;
|
||||||
|
using Orchard.Caching;
|
||||||
|
using Orchard.DisplayManagement.Implementation;
|
||||||
|
using Orchard.FileSystems.VirtualPath;
|
||||||
|
|
||||||
|
namespace TinyMce.Services {
|
||||||
|
public class TinyMceShapeDisplayEvent : ShapeDisplayEvents {
|
||||||
|
private readonly ICacheManager _cacheManager;
|
||||||
|
private readonly ISignals _signals;
|
||||||
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
|
private readonly IWorkContextAccessor _workContextAccessor;
|
||||||
|
|
||||||
|
private const string CacheKeyFormat = "tinymce-locales-{0}";
|
||||||
|
private const string DefaultLanguage = "en";
|
||||||
|
|
||||||
|
public TinyMceShapeDisplayEvent(
|
||||||
|
ICacheManager cacheManager,
|
||||||
|
IVirtualPathProvider virtualPathProvider,
|
||||||
|
IWorkContextAccessor workContextAccessor,
|
||||||
|
ISignals signals) {
|
||||||
|
_signals = signals;
|
||||||
|
_cacheManager = cacheManager;
|
||||||
|
_virtualPathProvider = virtualPathProvider;
|
||||||
|
_workContextAccessor = workContextAccessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Displaying(ShapeDisplayingContext context) {
|
||||||
|
if (String.CompareOrdinal(context.ShapeMetadata.Type, "Body_Editor") != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (String.CompareOrdinal(context.Shape.EditorFlavor, "html") != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Shape.Language = GetTinyMceLanguageIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetTinyMceLanguageIdentifier() {
|
||||||
|
var currentCulture = CultureInfo.GetCultureInfo(_workContextAccessor.GetContext().CurrentCulture);
|
||||||
|
|
||||||
|
if (currentCulture.Name.Equals(DefaultLanguage, StringComparison.OrdinalIgnoreCase))
|
||||||
|
return currentCulture.Name;
|
||||||
|
|
||||||
|
|
||||||
|
return _cacheManager.Get(string.Format(CacheKeyFormat, currentCulture.Name), ctx => {
|
||||||
|
ctx.Monitor(_signals.When("culturesChanged"));
|
||||||
|
|
||||||
|
var customLanguage = currentCulture.Name.Replace('-', '_');
|
||||||
|
|
||||||
|
var languageFiles = _virtualPathProvider
|
||||||
|
.ListFiles("~/modules/tinymce/scripts/langs")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (languageFiles.Any(x => x == string.Format("{0}.js", customLanguage)))
|
||||||
|
return customLanguage;
|
||||||
|
|
||||||
|
if (!DefaultLanguage.Equals(currentCulture.TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
languageFiles.Any(x => x == string.Format("{0}.js", currentCulture.TwoLetterISOLanguageName))) {
|
||||||
|
return currentCulture.TwoLetterISOLanguageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DefaultLanguage;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -48,6 +48,7 @@
|
|||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
@@ -181,6 +182,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ResourceManifest.cs" />
|
<Compile Include="ResourceManifest.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Services\TinyMceShapeDisplayEvent.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Body-Html.Editor.cshtml" />
|
<Content Include="Views\Body-Html.Editor.cshtml" />
|
||||||
|
@@ -1,35 +1,16 @@
|
|||||||
@using System.Globalization
|
@using Orchard.ContentManagement
|
||||||
@using Orchard.ContentManagement
|
|
||||||
@using Orchard.Environment.Descriptor.Models
|
@using Orchard.Environment.Descriptor.Models
|
||||||
@using Orchard.FileSystems.VirtualPath
|
|
||||||
@using Orchard.Localization
|
@using Orchard.Localization
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var shellDescriptor = WorkContext.Resolve<ShellDescriptor>();
|
var shellDescriptor = WorkContext.Resolve<ShellDescriptor>();
|
||||||
var virtualPathProvider = WorkContext.Resolve<IVirtualPathProvider>();
|
|
||||||
|
|
||||||
// Default language for TinyMCE
|
|
||||||
var language = "en";
|
|
||||||
var currentCulture = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture);
|
|
||||||
if (!currentCulture.Name.Equals("en-US", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
var customLanguage = currentCulture.Name.Replace('-', '_');
|
|
||||||
if (!language.Equals(customLanguage, StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
if (virtualPathProvider.TryFileExists(string.Format(@"\modules\tinymce\scripts\langs\{0}.js", customLanguage))) {
|
|
||||||
language = customLanguage;
|
|
||||||
}
|
|
||||||
else if (!language.Equals(currentCulture.TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase) &&
|
|
||||||
virtualPathProvider.TryFileExists(string.Format(@"\modules\tinymce\scripts\langs\{0}.js", currentCulture.TwoLetterISOLanguageName))) {
|
|
||||||
language = currentCulture.TwoLetterISOLanguageName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var mediaPickerEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaPicker") ? "true" : "false");
|
var mediaPickerEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaPicker") ? "true" : "false");
|
||||||
var mediaLibraryEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaLibrary") ? "true" : "false");
|
var mediaLibraryEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaLibrary") ? "true" : "false");
|
||||||
var directionality = '@WorkContext.GetTextDirection((IContent)Model.BodyPart.ContentItem)';
|
var directionality = '@WorkContext.GetTextDirection((IContent)Model.BodyPart.ContentItem)';
|
||||||
var language = '@language';
|
var language = '@Model.Language';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@{
|
@{
|
||||||
|
Reference in New Issue
Block a user