CSS classes can now be specified for widgets, fixes #5387

This commit is contained in:
Lombiq
2015-06-26 00:34:57 +02:00
parent 1aefd0fdbd
commit 4e7e274d85
4 changed files with 28 additions and 0 deletions

View File

@@ -59,6 +59,16 @@ namespace Orchard.Widgets.Drivers {
}
}
if (!String.IsNullOrEmpty(widgetPart.CssClasses)) {
var classNames = widgetPart.CssClasses.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < classNames.Length; i++) {
classNames[i] = classNames[i].Trim().HtmlClassify();
}
widgetPart.CssClasses = String.Join(" ", classNames);
}
_widgetsService.MakeRoomForWidgetPosition(widgetPart);
return Editor(widgetPart, shapeHelper);

View File

@@ -76,5 +76,13 @@ namespace Orchard.Widgets.Models {
/// </summary>
[HiddenInput(DisplayValue = false)]
public IEnumerable<LayerPart> AvailableLayers { get; set; }
/// <summary>
/// Css classes for the widget.
/// </summary>
public string CssClasses {
get { return this.Retrieve(x => x.CssClasses); }
set { this.Store(x => x.CssClasses, value); }
}
}
}

View File

@@ -42,6 +42,11 @@ namespace Orchard.Widgets {
displaying.ShapeMetadata.Alternates.Add("Widget__Name__" + widgetPart.Name);
}
// Adding other css classes to the widget.
if (!String.IsNullOrWhiteSpace(widgetPart.CssClasses)) {
widget.Classes.Add(widgetPart.CssClasses);
}
}
});
}

View File

@@ -27,3 +27,8 @@
@Html.TextBoxFor(widget => widget.Name, new { @class = "text" })
<span class="hint">@T("The technical name of the Widget, used for css class and alternates.")</span>
</fieldset>
<fieldset>
@Html.LabelFor(widget => widget.CssClasses, T("Css classes"))
@Html.TextBoxFor(widget => widget.CssClasses, new { @class = "text medium" })
<span class="hint">@T("Add custom css classes for the widget separated by spaces.")</span>
</fieldset>