github.com/kotovmak/go-admin@v1.1.1/template/types/display/carousel.go (about) 1 package display 2 3 import ( 4 "html/template" 5 "strconv" 6 7 "github.com/kotovmak/go-admin/template/types" 8 ) 9 10 type Carousel struct { 11 types.BaseDisplayFnGenerator 12 } 13 14 func init() { 15 types.RegisterDisplayFnGenerator("carousel", new(Carousel)) 16 } 17 18 func (c *Carousel) Get(args ...interface{}) types.FieldFilterFn { 19 return func(value types.FieldModel) interface{} { 20 fn := args[0].(types.FieldGetImgArrFn) 21 size := args[1].([]int) 22 23 width := "300" 24 height := "200" 25 26 if len(size) > 0 { 27 width = strconv.Itoa(size[0]) 28 } 29 30 if len(size) > 1 { 31 height = strconv.Itoa(size[1]) 32 } 33 34 images := fn(value.Value) 35 36 indicators := "" 37 items := "" 38 active := "" 39 40 for i, img := range images { 41 indicators += `<li data-target="#carousel-value-` + value.ID + `" data-slide-to="` + 42 strconv.Itoa(i) + `" class=""></li>` 43 if i == 0 { 44 active = " active" 45 } else { 46 active = "" 47 } 48 items += `<div class="item` + active + `"> 49 <img src="` + img + `" alt="" 50 style="max-width:` + width + `px;max-height:` + height + `px;display: block;margin-left: auto;margin-right: auto;" /> 51 <div class="carousel-caption"></div> 52 </div>` 53 } 54 55 return template.HTML(` 56 <div id="carousel-value-` + value.ID + `" class="carousel slide" data-ride="carousel" width="` + width + `" height="` + height + `" 57 style="padding: 5px;border: 1px solid #f4f4f4;background-color:white;width:` + width + `px;"> 58 <ol class="carousel-indicators"> 59 ` + indicators + ` 60 </ol> 61 <div class="carousel-inner"> 62 ` + items + ` 63 </div> 64 <a class="left carousel-control" href="#carousel-value-` + value.ID + `" data-slide="prev"> 65 <span class="fa fa-angle-left"></span> 66 </a> 67 <a class="right carousel-control" href="#carousel-value-` + value.ID + `" data-slide="next"> 68 <span class="fa fa-angle-right"></span> 69 </a> 70 </div> 71 `) 72 } 73 }