diff --git a/common/pages.go b/common/pages.go index 764e875a..7ca0ed84 100644 --- a/common/pages.go +++ b/common/pages.go @@ -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 diff --git a/common/routes_common.go b/common/routes_common.go index 4521a455..e20fa4df 100644 --- a/common/routes_common.go +++ b/common/routes_common.go @@ -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) } } } diff --git a/panel_routes.go b/panel_routes.go index 7194a45b..ce840949 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -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 { diff --git a/routes/topic.go b/routes/topic.go index 4a980a92..d2037052 100644 --- a/routes/topic.go +++ b/routes/topic.go @@ -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")