Commit bb9f2860 authored by Siong-Ui Te's avatar Siong-Ui Te

move common frontend code to library

parent d77f27cd
......@@ -101,6 +101,7 @@ lib_pali:
@echo "\033[92mInstalling common lib used in this project ...\033[0m"
go get -u github.com/siongui/gopalilib/dicutil
go get -u github.com/siongui/gopalilib/lib/jsgettext
go get -u github.com/siongui/gopalilib/libfrontend
lib_gtmpl:
@echo "\033[92mInstalling Go html/template with gettext support ...\033[0m"
......
......@@ -6,6 +6,7 @@ import (
. "github.com/siongui/godom"
"github.com/siongui/gopalilib/lib"
"github.com/siongui/gopalilib/lib/jsgettext"
"github.com/siongui/gopalilib/libfrontend"
)
func getFinalShowLocale() string {
......@@ -28,7 +29,7 @@ func xmlAction(text, action string) {
// Load the xml file using synchronous (third param is set to false) XMLHttpRequest
myXMLHTTPRequest := NewXMLHttpRequest()
myXMLHTTPRequest.Open("GET", ActionXmlUrl(action), false)
myXMLHTTPRequest.Open("GET", libfrontend.ActionXmlUrl(action), false)
myXMLHTTPRequest.Send()
xmlDoc := myXMLHTTPRequest.ResponseXML()
......
package main
import (
. "github.com/siongui/godom"
dic "github.com/siongui/gopalilib/lib/dictionary"
)
func ActionXmlUrl(action string) string {
return "https://siongui.github.io/tipitaka-romn/" + action
}
func GetXslUrl() string {
return "https://siongui.github.io/tipitaka-romn/cscd/tipitaka-latn.xsl"
}
func HttpWordJsonPath(word string) string {
if isOffline() {
return "/json/" + word + ".json"
}
return "https://siongui.github.io/xemaauj9k5qn34x88m4h/" + word + ".json"
}
func isOffline() bool {
return Window.Location().Hostname() == "localhost" && Window.Location().Port() == "8080"
}
func wordDictionaryUrl(word string) string {
return "https://dictionary.sutta.org" + dic.WordUrlPath(word)
}
......@@ -7,10 +7,11 @@ import (
. "github.com/siongui/godom"
"github.com/siongui/gopalilib/lib"
"github.com/siongui/gopalilib/lib/dicmgr"
"github.com/siongui/gopalilib/libfrontend"
)
func wordLinkHtml(word string) string {
return "<a href='" + wordDictionaryUrl(word) + "' target='_blank'>" + word + "</a>"
return "<a href='" + libfrontend.DictionarySuttaWordUrl(word) + "' target='_blank'>" + word + "</a>"
}
const pwt = `
......@@ -38,7 +39,7 @@ func possibleWordClickHandler(word string) {
SetModalContent("Loading " + wordLinkHtml(word) + " ...")
go func() {
wi, err := lib.HttpGetWordJson(HttpWordJsonPath(word))
wi, err := lib.HttpGetWordJson(libfrontend.HttpWordJsonPath(word))
if err != nil {
SetModalContent("Fail to Get " + word + ": " + err.Error())
return
......@@ -76,7 +77,7 @@ func GetPossibleWordsHtml(word string, possibleWords []string) string {
func showWordDefinitionInModal(word string) {
//showLookingUp()
//defer hideLookingUp()
wi, err := lib.HttpGetWordJson(HttpWordJsonPath(word))
wi, err := lib.HttpGetWordJson(libfrontend.HttpWordJsonPath(word))
if err != nil {
SetModalContent("Fail to Get " + word + ": " + err.Error())
return
......
......@@ -2,6 +2,7 @@ package main
import (
. "github.com/siongui/godom"
"github.com/siongui/gopalilib/libfrontend"
)
var xsltProcessor *XSLTProcessor
......@@ -15,7 +16,7 @@ func SetupXSLTProcessor() {
// Load the xsl file using synchronous (third param is set to false) XMLHttpRequest
myXMLHTTPRequest := NewXMLHttpRequest()
myXMLHTTPRequest.Open("GET", GetXslUrl(), false)
myXMLHTTPRequest.Open("GET", libfrontend.GetXslUrl(), false)
myXMLHTTPRequest.Send()
xslStylesheet := myXMLHTTPRequest.ResponseXML()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment