mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
html
This commit is contained in:
+33
-6
@@ -1533,13 +1533,40 @@ async function saveBanner(event) {
|
|||||||
bannerVisible.value = bannerVisibility.checked ? 'true' : 'false';
|
bannerVisible.value = bannerVisibility.checked ? 'true' : 'false';
|
||||||
}
|
}
|
||||||
|
|
||||||
formData.append('text', bannerText ? bannerText.value : '');
|
// Get HTML content from the contenteditable div
|
||||||
formData.append('link', bannerLink ? bannerLink.value : '');
|
const bannerTextContent = bannerText ? bannerText.innerHTML : '';
|
||||||
formData.append('isVisible', bannerVisible ? bannerVisible.value : 'true');
|
|
||||||
|
|
||||||
// Always send the banner visibility
|
// Add banner content with proper field names
|
||||||
formData.append('isVisible', bannerVisible ? bannerVisible.value : 'true');
|
formData.append('Text', bannerTextContent);
|
||||||
formData.append('style[isVisible]', bannerVisible ? bannerVisible.value : 'true');
|
formData.append('Link', bannerLink ? bannerLink.value : '');
|
||||||
|
formData.append('IsVisible', bannerVisible ? bannerVisible.value : 'true');
|
||||||
|
|
||||||
|
// Add style values with proper field names
|
||||||
|
formData.append('Style[BackgroundColor]', bannerBgColorPicker?.value || '');
|
||||||
|
formData.append('Style[TextColor]', bannerTextColorPicker?.value || '');
|
||||||
|
formData.append('Style[TextAlign]', bannerTextAlign?.value || 'left');
|
||||||
|
formData.append('Style[FontSize]', bannerFontSize?.value || '16');
|
||||||
|
formData.append('Style[Padding]', bannerPadding?.value || '20');
|
||||||
|
formData.append('Style[Margin]', bannerMargin?.value || '20');
|
||||||
|
formData.append('Style[BorderRadius]', bannerBorderRadius?.value || '8');
|
||||||
|
formData.append('Style[IsVisible]', bannerVisible ? bannerVisible.value : 'true');
|
||||||
|
formData.append('Style[ImagePosition]', currentImagePosition || 'right');
|
||||||
|
formData.append('Style[ImageX]', currentImageX || '0');
|
||||||
|
formData.append('Style[ImageY]', currentImageY || '0');
|
||||||
|
|
||||||
|
// Add template styles if available
|
||||||
|
if (currentTemplate && templateConfigs[currentTemplate]) {
|
||||||
|
const template = templateConfigs[currentTemplate];
|
||||||
|
if (template.backgroundColor) formData.append('Style[BackgroundColor]', template.backgroundColor);
|
||||||
|
if (template.textColor) formData.append('Style[TextColor]', template.textColor);
|
||||||
|
if (template.textAlign) formData.append('Style[TextAlign]', template.textAlign);
|
||||||
|
if (template.fontSize) formData.append('Style[FontSize]', template.fontSize);
|
||||||
|
if (template.padding) formData.append('Style[Padding]', template.padding);
|
||||||
|
if (template.margin) formData.append('Style[Margin]', template.margin);
|
||||||
|
if (template.borderRadius) formData.append('Style[BorderRadius]', template.borderRadius);
|
||||||
|
if (template.background) formData.append('Style[Background]', template.background);
|
||||||
|
if (template.containerStyle) formData.append('Style[ContainerStyle]', template.containerStyle);
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure templateConfigs is defined and has the default template
|
// Ensure templateConfigs is defined and has the default template
|
||||||
if (typeof templateConfigs === 'undefined') {
|
if (typeof templateConfigs === 'undefined') {
|
||||||
|
|||||||
@@ -54,28 +54,28 @@ func ensureDirs() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BannerContent struct {
|
type BannerContent struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"Text"`
|
||||||
Image string `json:"image,omitempty"`
|
Image string `json:"Image,omitempty"`
|
||||||
Link string `json:"link,omitempty"`
|
Link string `json:"Link,omitempty"`
|
||||||
Style BannerStyle `json:"style"`
|
Style BannerStyle `json:"Style"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BannerStyle struct {
|
type BannerStyle struct {
|
||||||
BackgroundColor string `json:"backgroundColor"`
|
BackgroundColor string `json:"BackgroundColor"`
|
||||||
TextColor string `json:"textColor"`
|
TextColor string `json:"TextColor"`
|
||||||
TextAlign string `json:"textAlign"`
|
TextAlign string `json:"TextAlign"`
|
||||||
FontSize string `json:"fontSize"`
|
FontSize string `json:"FontSize"`
|
||||||
Padding string `json:"padding"`
|
Padding string `json:"Padding"`
|
||||||
Margin string `json:"margin"`
|
Margin string `json:"Margin"`
|
||||||
BorderRadius string `json:"borderRadius"`
|
BorderRadius string `json:"BorderRadius"`
|
||||||
IsVisible bool `json:"isVisible"`
|
IsVisible bool `json:"IsVisible"`
|
||||||
ImageWidth int `json:"imageWidth"` // Width in pixels
|
ImageWidth int `json:"ImageWidth"` // Width in pixels
|
||||||
ImageHeight int `json:"imageHeight"` // Height in pixels
|
ImageHeight int `json:"ImageHeight"` // Height in pixels
|
||||||
ImagePosition string `json:"imagePosition"` // center, left, right
|
ImagePosition string `json:"ImagePosition"` // center, left, right
|
||||||
ImageX int `json:"imageX"` // X position for custom
|
ImageX int `json:"ImageX"` // X position for custom
|
||||||
ImageY int `json:"imageY"` // Y position for custom
|
ImageY int `json:"ImageY"` // Y position for custom
|
||||||
Background string `json:"background,omitempty"`
|
Background string `json:"Background,omitempty"`
|
||||||
ContainerStyle string `json:"containerStyle,omitempty"`
|
ContainerStyle string `json:"ContainerStyle,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -193,25 +193,25 @@ func UpdateBannerHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Create a new banner with default values
|
// Create a new banner with default values
|
||||||
newBanner := BannerContent{
|
newBanner := BannerContent{
|
||||||
Text: r.FormValue("text"),
|
Text: r.FormValue("Text"),
|
||||||
Link: r.FormValue("link"),
|
Link: r.FormValue("Link"),
|
||||||
Style: BannerStyle{
|
Style: BannerStyle{
|
||||||
// Parse style values from form
|
// Parse style values from form
|
||||||
BackgroundColor: r.FormValue("style[backgroundColor]"),
|
BackgroundColor: r.FormValue("style[BackgroundColor]"),
|
||||||
TextColor: r.FormValue("style[textColor]"),
|
TextColor: r.FormValue("style[TextColor]"),
|
||||||
TextAlign: r.FormValue("style[textAlign]"),
|
TextAlign: r.FormValue("style[TextAlign]"),
|
||||||
FontSize: r.FormValue("style[fontSize]"),
|
FontSize: r.FormValue("style[FontSize]"),
|
||||||
Padding: r.FormValue("style[padding]"),
|
Padding: r.FormValue("style[Padding]"),
|
||||||
Margin: r.FormValue("style[margin]"),
|
Margin: r.FormValue("style[Margin]"),
|
||||||
BorderRadius: r.FormValue("style[borderRadius]"),
|
BorderRadius: r.FormValue("style[BorderRadius]"),
|
||||||
IsVisible: r.FormValue("isVisible") == "true" || r.FormValue("style[isVisible]") == "true",
|
IsVisible: r.FormValue("IsVisible") == "true" || r.FormValue("style[IsVisible]") == "true",
|
||||||
// Add image position fields
|
// Add image position fields
|
||||||
ImagePosition: r.FormValue("style[imagePosition]"),
|
ImagePosition: r.FormValue("style[ImagePosition]"),
|
||||||
ImageX: parseIntOrDefault(r.FormValue("style[imageX]"), 0),
|
ImageX: parseIntOrDefault(r.FormValue("style[ImageX]"), 0),
|
||||||
ImageY: parseIntOrDefault(r.FormValue("style[imageY]"), 0),
|
ImageY: parseIntOrDefault(r.FormValue("style[ImageY]"), 0),
|
||||||
// Additional style fields
|
// Additional style fields
|
||||||
Background: r.FormValue("style[background]"),
|
Background: r.FormValue("style[Background]"),
|
||||||
ContainerStyle: r.FormValue("style[containerStyle]"),
|
ContainerStyle: r.FormValue("style[ContainerStyle]"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+53
-15
@@ -87,19 +87,16 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Start building banner content
|
// Get or create banner container with link
|
||||||
let content = `
|
const bannerContainerEl = document.getElementById('bannerContainer');
|
||||||
<div class="banner-content" style="
|
if (bannerContainerEl) {
|
||||||
padding: ${padding}px;
|
bannerContainerEl.style.position = 'relative';
|
||||||
margin: ${margin}px;
|
bannerContainerEl.style.overflow = 'hidden';
|
||||||
background: ${backgroundColor};
|
|
||||||
color: ${textColor};
|
// Add the link to the entire banner container
|
||||||
border-radius: ${borderRadius}px;
|
if (bannerLink) {
|
||||||
${style.containerStyle || ''}
|
bannerContainerEl.innerHTML = `
|
||||||
position: relative;
|
<a href="${bannerLink}" target="_blank" style="
|
||||||
overflow: hidden;
|
|
||||||
">
|
|
||||||
${banner.link ? `<a href="${banner.link}" target="_blank" style="
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -108,8 +105,40 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
"></a>` : ''}
|
"></a>
|
||||||
|
<div id="bannerInnerContent"></div>
|
||||||
`;
|
`;
|
||||||
|
} else {
|
||||||
|
bannerContainerEl.innerHTML = '<div id="bannerInnerContent"></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start building banner content
|
||||||
|
let content = '';
|
||||||
|
|
||||||
|
// Only show the banner if it's visible
|
||||||
|
if (banner.Style && banner.Style.IsVisible !== false) {
|
||||||
|
content = `
|
||||||
|
<div class="banner-content" style="
|
||||||
|
padding: ${padding}px;
|
||||||
|
margin: ${margin}px;
|
||||||
|
background: ${backgroundColor};
|
||||||
|
color: ${textColor};
|
||||||
|
border-radius: ${borderRadius}px;
|
||||||
|
${style.containerStyle || ''}
|
||||||
|
position: relative;
|
||||||
|
">
|
||||||
|
<div class="banner-html-content" style="
|
||||||
|
color: ${textColor};
|
||||||
|
font-size: ${style.fontSize || '16px'};
|
||||||
|
text-align: ${style.textAlign || 'left'};
|
||||||
|
line-height: 1.5;
|
||||||
|
">
|
||||||
|
${bannerText}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle image if it exists
|
// Handle image if it exists
|
||||||
const bannerText = banner.text || banner.Text || '';
|
const bannerText = banner.text || banner.Text || '';
|
||||||
@@ -249,7 +278,16 @@
|
|||||||
// Text is already added in the previous conditions
|
// Text is already added in the previous conditions
|
||||||
|
|
||||||
// Set the content and make banner visible
|
// Set the content and make banner visible
|
||||||
bannerContent.innerHTML = content;
|
const innerContent = bannerContainerEl ?
|
||||||
|
(bannerContainerEl.querySelector('#bannerInnerContent') || bannerContainerEl) :
|
||||||
|
bannerContent;
|
||||||
|
|
||||||
|
if (banner.Style && banner.Style.IsVisible !== false) {
|
||||||
|
innerContent.innerHTML = content;
|
||||||
|
bannerContent.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
bannerContent.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
// Apply custom font if specified in template
|
// Apply custom font if specified in template
|
||||||
if (style.fontFamily) {
|
if (style.fontFamily) {
|
||||||
|
|||||||
Reference in New Issue
Block a user