Commit 6375fe24 authored by Siong-Ui Te's avatar Siong-Ui Te

move setting frontend code to another package

parent a6b775bb
......@@ -13,16 +13,44 @@ addons:
- make
- git
- gettext
install:
- cd tipitaka/
- make install
script:
- make make-sutta
deploy:
- provider: pages
repo: siongui/tipitaka.sutta.org
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: tipitaka/website
on:
branch: master
# https://docs.travis-ci.com/user/build-matrix/
jobs:
include:
# for dictionary.online-dhamma.net
- env: TARGET_WEBSITE=dhamma
install:
- cd dictionary/
- make install
script:
- make make-dhamma
after_success:
- make custom_dhamma_deploy
# for dictionary.sutta.org
- env: TARGET_WEBSITE=sutta
install:
- cd dictionary/
- make install
script:
- make make-sutta
after_success:
- make custom_sutta_deploy
# dpl v2 (not working for lots of symlinks)
#deploy:
# - provider: pages:git
# repo: siongui/dictionary.sutta.org
# keep_history: false
# token: $GITHUB_TOKEN
# local_dir: website
# on:
# branch: master
# edge: true
# verbose: true
# dpl v1 (not working for lots of symlinks)
#deploy:
# - provider: pages
# repo: siongui/dictionary.sutta.org
# skip_cleanup: true
# github_token: $GITHUB_TOKEN
# local_dir: website
# on:
# branch: master
......@@ -268,6 +268,7 @@ lib_pali:
go get -u github.com/siongui/gopalilib/lib/jsgettext
go get -u github.com/siongui/gopaliwordvfs
go get -u github.com/siongui/gopalilib/libfrontend/velthuis
go get -u github.com/siongui/gopalilib/libfrontend/setting
lib_gtmpl:
@echo "\033[92mInstalling Go html/template with gettext support ...\033[0m"
......
......@@ -10,7 +10,6 @@ import (
)
var supportedLocales = []string{"en_US", "zh_TW", "vi_VN", "fr_FR"}
var navigatorLanguages = Window.Navigator().Languages()
func TranslateDocument(locale string) {
elms := Document.QuerySelectorAll("[data-default-string]")
......@@ -39,7 +38,7 @@ func getFinalShowLocale() string {
// show language according to site url and NavigatorLanguages API
locale := Document.GetElementById("site-info").Dataset().Get("locale").String()
if locale == "" {
return jsgettext.DetermineLocaleByNavigatorLanguages(navigatorLanguages, supportedLocales)
return jsgettext.DetermineLocaleByNavigatorLanguages(Window.Navigator().Languages(), supportedLocales)
}
return locale
}
......
......@@ -6,6 +6,7 @@ import (
. "github.com/siongui/godom"
"github.com/siongui/gopalilib/lib/dicmgr"
dic "github.com/siongui/gopalilib/lib/dictionary"
"github.com/siongui/gopalilib/libfrontend/setting"
"github.com/siongui/gopalilib/libfrontend/velthuis"
sg "github.com/siongui/gopherjs-input-suggest"
)
......@@ -29,7 +30,8 @@ func handleInputKeyUp(e Event) {
func main() {
setupNavbar()
setupSetting()
setting.SetStorageKeyName("PaliDictionarySetting")
setting.SetupPaliSetting()
setupKeypad()
// add pali input method to input text element
......
package main
/*
References:
https://github.com/go-humble/locstor
https://www.google.com/search?q=localstorage
https://developer.mozilla.org/en-US/docs/Web/API/Storage
https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
*/
import (
"github.com/gopherjs/gopherjs/js"
"github.com/siongui/gopalilib/lib"
)
var localStorage = js.Global.Get("localStorage")
func savePaliDictionarySetting(setting lib.PaliSetting) {
str, _ := lib.PaliSettingToJsonString(setting)
localStorage.Set("PaliDictionarySetting", str)
}
func setupSetting() {
d := js.Global.Get("document")
isPreview := d.Call("getElementById", "isShowWordPreview")
p2en := d.Call("getElementById", "p2en")
p2ja := d.Call("getElementById", "p2ja")
p2zh := d.Call("getElementById", "p2zh")
p2vi := d.Call("getElementById", "p2vi")
p2my := d.Call("getElementById", "p2my")
dicLangOrder := d.Call("getElementById", "dicLangOrder")
setting := lib.GetDefaultPaliSetting()
// check if there is saved setting in user browser
if localStorage.Get("PaliDictionarySetting") == js.Undefined {
// no setting saved, use default setting
setting.IsShowWordPreview = isPreview.Get("checked").Bool()
setting.P2en = p2en.Get("checked").Bool()
setting.P2ja = p2ja.Get("checked").Bool()
setting.P2zh = p2zh.Get("checked").Bool()
setting.P2vi = p2vi.Get("checked").Bool()
setting.P2my = p2my.Get("checked").Bool()
setting.DicLangOrder = dicLangOrder.Get("options").Call("item",
dicLangOrder.Get("selectedIndex").Int()).Get("value").String()
savePaliDictionarySetting(setting)
} else {
// use saved setting
//localStorage.Call("getItem", "PaliDictionarySetting").String()
setting, _ = lib.JsonStringToPaliSetting(localStorage.Get("PaliDictionarySetting").String())
isPreview.Set("checked", setting.IsShowWordPreview)
p2en.Set("checked", setting.P2en)
p2ja.Set("checked", setting.P2ja)
p2zh.Set("checked", setting.P2zh)
p2vi.Set("checked", setting.P2vi)
p2my.Set("checked", setting.P2my)
dicLangOrder.Set("value", setting.DicLangOrder)
}
isPreview.Call("addEventListener", "click", func(event *js.Object) {
setting.IsShowWordPreview = isPreview.Get("checked").Bool()
savePaliDictionarySetting(setting)
})
// https://stackoverflow.com/questions/4471401/getting-value-of-html-checkbox-from-onclick-onchange-events
p2en.Call("addEventListener", "click", func(event *js.Object) {
setting.P2en = p2en.Get("checked").Bool()
savePaliDictionarySetting(setting)
})
p2ja.Call("addEventListener", "click", func(event *js.Object) {
setting.P2ja = p2ja.Get("checked").Bool()
savePaliDictionarySetting(setting)
})
p2zh.Call("addEventListener", "click", func(event *js.Object) {
setting.P2zh = p2zh.Get("checked").Bool()
savePaliDictionarySetting(setting)
})
p2vi.Call("addEventListener", "click", func(event *js.Object) {
setting.P2vi = p2vi.Get("checked").Bool()
savePaliDictionarySetting(setting)
})
p2my.Call("addEventListener", "click", func(event *js.Object) {
setting.P2my = p2my.Get("checked").Bool()
savePaliDictionarySetting(setting)
})
dicLangOrder.Call("addEventListener", "change", func(event *js.Object) {
setting.DicLangOrder = dicLangOrder.Get("options").Call("item",
dicLangOrder.Get("selectedIndex").Int()).Get("value").String()
savePaliDictionarySetting(setting)
})
}
func getSetting() lib.PaliSetting {
setting, _ := lib.JsonStringToPaliSetting(localStorage.Get("PaliDictionarySetting").String())
return setting
}
......@@ -4,6 +4,7 @@ import (
. "github.com/siongui/godom"
"github.com/siongui/gopalilib/lib"
"github.com/siongui/gopalilib/lib/dicmgr"
"github.com/siongui/gopalilib/libfrontend/setting"
sg "github.com/siongui/gopherjs-input-suggest"
)
......@@ -24,14 +25,14 @@ func httpGetWordJson2(word string) {
return
}
setWordPreviewUI(word, dicmgr.GetWordPreviewHtml(word, wi, getSetting(), navigatorLanguages))
setWordPreviewUI(word, dicmgr.GetWordPreviewHtml(word, wi, setting.LoadPaliSetting(), Window.Navigator().Languages()))
}
func setupWordPreview() {
wordPreviewElm = Document.QuerySelector(".suggestedWordPreview")
sg.OnHighlightSelectedWord(func(word string) {
//println(word)
if !getSetting().IsShowWordPreview {
if !setting.LoadPaliSetting().IsShowWordPreview {
return
}
//println("show word preview")
......
......@@ -5,6 +5,7 @@ import (
"github.com/siongui/gopalilib/lib"
"github.com/siongui/gopalilib/lib/dicmgr"
dic "github.com/siongui/gopalilib/lib/dictionary"
"github.com/siongui/gopalilib/libfrontend/setting"
)
func hideLookingUp() {
......@@ -33,5 +34,5 @@ func httpGetWordJson(w string, changeUrl bool) {
}
mainContent.RemoveAllChildNodes()
mainContent.Set("innerHTML", dicmgr.GetWordDefinitionHtml(wi, getSetting(), navigatorLanguages))
mainContent.Set("innerHTML", dicmgr.GetWordDefinitionHtml(wi, setting.LoadPaliSetting(), Window.Navigator().Languages()))
}
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