Added the AddScript and AddSheet methods to *HeaderVars and replaced the manual appends with them.
This commit is contained in:
parent
b32e8d6c21
commit
ca935d61a8
|
@ -7,16 +7,12 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// TODO: Implement this and use it
|
||||
// TODO: Allow resources in spots other than /static/ and possibly even external domains (e.g. CDNs)
|
||||
type HeaderResource struct {
|
||||
Path string
|
||||
Preload bool
|
||||
}
|
||||
|
||||
// TODO: Preload Trumboyg on Cosora on the forum list
|
||||
type HeaderVars struct {
|
||||
NoticeList []string
|
||||
Scripts []string
|
||||
NoticeList []string
|
||||
Scripts []string
|
||||
//PreloadScripts []string
|
||||
Stylesheets []string
|
||||
Widgets PageWidgets
|
||||
Site *site
|
||||
|
@ -30,6 +26,18 @@ type HeaderVars struct {
|
|||
ExtData ExtData
|
||||
}
|
||||
|
||||
func (header *HeaderVars) AddScript(name string) {
|
||||
header.Scripts = append(header.Scripts, name)
|
||||
}
|
||||
|
||||
/*func (header *HeaderVars) PreloadScript(name string) {
|
||||
header.PreloadScripts = append(header.PreloadScripts, name)
|
||||
}*/
|
||||
|
||||
func (header *HeaderVars) AddSheet(name string) {
|
||||
header.Stylesheets = append(header.Stylesheets, name)
|
||||
}
|
||||
|
||||
// TODO: Add this to routes which don't use templates. E.g. Json APIs.
|
||||
type HeaderLite struct {
|
||||
Site *site
|
||||
|
|
|
@ -122,7 +122,7 @@ func panelUserCheck(w http.ResponseWriter, r *http.Request, user *User) (headerV
|
|||
}
|
||||
// TODO: We should probably initialise headerVars.ExtData
|
||||
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, theme.Name+"/panel.css")
|
||||
headerVars.AddSheet(theme.Name + "/panel.css")
|
||||
if len(theme.Resources) > 0 {
|
||||
rlist := theme.Resources
|
||||
for _, resource := range rlist {
|
||||
|
@ -130,9 +130,9 @@ func panelUserCheck(w http.ResponseWriter, r *http.Request, user *User) (headerV
|
|||
extarr := strings.Split(resource.Name, ".")
|
||||
ext := extarr[len(extarr)-1]
|
||||
if ext == "css" {
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, resource.Name)
|
||||
headerVars.AddSheet(resource.Name)
|
||||
} else if ext == "js" {
|
||||
headerVars.Scripts = append(headerVars.Scripts, resource.Name)
|
||||
headerVars.AddScript(resource.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,9 +231,9 @@ func userCheck(w http.ResponseWriter, r *http.Request, user *User) (headerVars *
|
|||
extarr := strings.Split(resource.Name, ".")
|
||||
ext := extarr[len(extarr)-1]
|
||||
if ext == "css" {
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, resource.Name)
|
||||
headerVars.AddSheet(resource.Name)
|
||||
} else if ext == "js" {
|
||||
headerVars.Scripts = append(headerVars.Scripts, resource.Name)
|
||||
headerVars.AddScript(resource.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -670,9 +670,9 @@ func routePanelAnalyticsViews(w http.ResponseWriter, r *http.Request, user commo
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -710,9 +710,9 @@ func routePanelAnalyticsRouteViews(w http.ResponseWriter, r *http.Request, user
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -751,9 +751,9 @@ func routePanelAnalyticsAgentViews(w http.ResponseWriter, r *http.Request, user
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -798,9 +798,9 @@ func routePanelAnalyticsForumViews(w http.ResponseWriter, r *http.Request, user
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -847,9 +847,9 @@ func routePanelAnalyticsSystemViews(w http.ResponseWriter, r *http.Request, user
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -892,9 +892,9 @@ func routePanelAnalyticsLanguageViews(w http.ResponseWriter, r *http.Request, us
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -937,9 +937,9 @@ func routePanelAnalyticsReferrerViews(w http.ResponseWriter, r *http.Request, us
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -976,9 +976,9 @@ func routePanelAnalyticsTopics(w http.ResponseWriter, r *http.Request, user comm
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
@ -1016,9 +1016,9 @@ func routePanelAnalyticsPosts(w http.ResponseWriter, r *http.Request, user commo
|
|||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "analytics.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
headerVars.AddScript("analytics.js")
|
||||
|
||||
timeRange, err := panelAnalyticsTimeRange(r.FormValue("timeRange"))
|
||||
if err != nil {
|
||||
|
|
|
@ -74,8 +74,8 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, urlBit
|
|||
}
|
||||
headerVars.Zone = "view_topic"
|
||||
// TODO: Only include these on pages with polls
|
||||
headerVars.Stylesheets = append(headerVars.Stylesheets, "chartist/chartist.min.css")
|
||||
headerVars.Scripts = append(headerVars.Scripts, "chartist/chartist.min.js")
|
||||
headerVars.AddSheet("chartist/chartist.min.css")
|
||||
headerVars.AddScript("chartist/chartist.min.js")
|
||||
|
||||
topic.ContentHTML = common.ParseMessage(topic.Content, topic.ParentID, "forums")
|
||||
topic.ContentLines = strings.Count(topic.Content, "\n")
|
||||
|
|
Loading…
Reference in New Issue