video_banner.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package containers
  2. import (
  3. "fmt"
  4. "github.com/iancoleman/strcase"
  5. "github.com/jinzhu/inflection"
  6. "github.com/qor5/admin/media/media_library"
  7. "github.com/qor5/admin/pagebuilder"
  8. "github.com/qor5/web"
  9. . "github.com/theplant/htmlgo"
  10. )
  11. type VideoBanner struct {
  12. ID uint
  13. AddTopSpace bool
  14. AddBottomSpace bool
  15. AnchorID string
  16. Video media_library.MediaBox `sql:"type:text;"`
  17. BackgroundVideo media_library.MediaBox `sql:"type:text;"`
  18. MobileBackgroundVideo media_library.MediaBox `sql:"type:text;"`
  19. VideoCover media_library.MediaBox `sql:"type:text;"`
  20. MobileVideoCover media_library.MediaBox `sql:"type:text;"`
  21. Heading string
  22. PopupText string
  23. Text string
  24. LinkText string
  25. Link string
  26. }
  27. func (*VideoBanner) TableName() string {
  28. return "container_video_banners"
  29. }
  30. func RegisterVideoBannerContainer(pb *pagebuilder.Builder) {
  31. vb := pb.RegisterContainer("Video Banner").
  32. RenderFunc(func(obj interface{}, input *pagebuilder.RenderInput, ctx *web.EventContext) HTMLComponent {
  33. v := obj.(*VideoBanner)
  34. return VideoBannerBody(v, input)
  35. })
  36. ed := vb.Model(&VideoBanner{}).Editing("AddTopSpace", "AddBottomSpace", "AnchorID", "Video", "BackgroundVideo", "MobileBackgroundVideo", "VideoCover", "MobileVideoCover", "Heading", "PopupText", "Text", "LinkText", "Link")
  37. ed.Field("Heading").ComponentFunc(TextArea)
  38. ed.Field("Text").ComponentFunc(TextArea)
  39. }
  40. func VideoBannerBody(data *VideoBanner, input *pagebuilder.RenderInput) (body HTMLComponent) {
  41. body = ContainerWrapper(
  42. fmt.Sprintf(inflection.Plural(strcase.ToKebab("VideoBanner"))+"_%v", data.ID), data.AnchorID, "container-video_banner",
  43. "", "", "",
  44. "", data.AddTopSpace, data.AddBottomSpace, input.IsEditor, input.IsReadonly, "",
  45. Div().Class("container-video_banner-mask"), VideoBannerHeadBody(data), VideoBannerFootBody(data),
  46. // If(data.PopupText != "", VideoBannerPopupBody(data)),
  47. )
  48. return
  49. }
  50. func VideoBannerHeadBody(data *VideoBanner) HTMLComponent {
  51. return Div(
  52. Div().Class("container-video_banner-background container-video_banner-background-image"),
  53. Video(
  54. Source("").Src(data.BackgroundVideo.URL()),
  55. ).Class("container-video_banner-background container-video_banner-background-desktop").
  56. Attr("preload", "none").Attr("loop", "true").Attr("muted", "true").Attr("playsinline", "true").Attr("webkit-playsinline", "true").Attr("data-cover-image-url", data.VideoCover.URL()),
  57. Video(
  58. Source("").Src(data.MobileBackgroundVideo.URL()),
  59. ).Class("container-video_banner-background container-video_banner-background-mobile").
  60. Attr("preload", "none").Attr("loop", "true").Attr("muted", "true").Attr("playsinline", "true").Attr("webkit-playsinline", "true").Attr("data-cover-image-url", data.MobileVideoCover.URL()),
  61. Div(
  62. If(data.Heading != "", H1(data.Heading).Class("container-video_banner-heading")),
  63. // If(data.PopupText != "", A(Span(data.PopupText), LINK_ARROW_SVG).Class("container-video_banner-full link-arrow")),
  64. ).Class("container-video_banner-head-wrap container-wrapper").Style("display:none;"),
  65. ).Class("container-video_banner-head")
  66. }
  67. func VideoBannerFootBody(data *VideoBanner) HTMLComponent {
  68. return Div(
  69. Div(
  70. P(Text(data.Text)).Class("container-video_banner-text p-large"),
  71. LinkTextWithArrow(data.LinkText, data.Link),
  72. ).Class("container-wrapper"),
  73. ).Class("container-video_banner-foot")
  74. }