コード例 #1
0
ファイル: showwordbytpl.go プロジェクト: siongui/pali
func showSuggestedWordsByTemplate(words []string) {
	gojs.RemoveAllChildNodes(mainContent)

	t1, _ := template.New("suggestedWords").Parse(lib.HtmlTemplateSuggestedWords)
	var buf bytes.Buffer
	t1.Execute(&buf, words)
	mainContent.Set("innerHTML", buf.String())
}
コード例 #2
0
ファイル: showwordbytpl.go プロジェクト: siongui/pali
func showWordByTemplate(wi lib.BookIdWordExps) {
	gojs.RemoveAllChildNodes(mainContent)

	bnwes := lib.IdExps2BookNameWordExps(
		lib.BookIdWordExps2IdExpsAccordingToSetting(wi, bookIdAndInfos, getSetting(), navigatorLanguages),
		bookIdAndInfos)
	t1, _ := template.New("wordExplanation").Parse(lib.HtmlTemplateBookNameWordExps)
	// Google Search: go html template output string
	// https://groups.google.com/forum/#!topic/golang-nuts/dSFHCV-e6Nw
	var buf bytes.Buffer
	t1.Execute(&buf, bnwes)
	mainContent.Set("innerHTML", buf.String())
}
コード例 #3
0
ファイル: navbar.go プロジェクト: siongui/pali
func setupNavbar() {
	jsgettext.SetupTranslationMapping(string(poJsonBlob))

	d := js.Global.Get("document")
	about := d.Call("getElementById", "about")
	punch := d.Call("getElementById", "punch")
	settingMenu := d.Call("querySelector", ".setting-menu")

	// about link
	nodeList := d.Call("querySelectorAll", ".about-link")
	length := nodeList.Get("length").Int()
	for i := 0; i < length; i++ {
		link := nodeList.Call("item", i)
		link.Call("addEventListener", "click", func(event *js.Object) {
			// prevent follow link to #
			event.Call("preventDefault")

			// load about content
			gojs.RemoveAllChildNodes(mainContent)
			mainContent.Set("innerHTML", about.Get("innerHTML").String())

			// close toggle window on mobile device
			punch.Set("checked", true)
		})
	}

	// setting link
	nodeList = d.Call("querySelectorAll", ".setting-link")
	length = nodeList.Get("length").Int()
	for i := 0; i < length; i++ {
		link := nodeList.Call("item", i)
		link.Call("addEventListener", "click", func(event *js.Object) {
			// prevent follow link to #
			event.Call("preventDefault")

			// toggle arrow
			downArrow := link.Get("firstChild")
			downArrow.Get("classList").Call("toggle", "invisible")
			// right arrow
			downArrow.Get("nextSibling").Get("classList").Call("toggle", "invisible")
			// setting menu
			settingMenu.Get("classList").Call("toggle", "invisible")

			// close toggle window on mobile device
			punch.Set("checked", true)
		})
	}

	// language select
	ls := d.Call("getElementById", "lang-select")
	ls.Call("addEventListener", "change", func(event *js.Object) {
		locale := ls.Get("options").Call("item", ls.Get("selectedIndex").Int()).Get("value").String()
		jsgettext.Translate(locale)
	})

	// mobile language select
	nodeList = d.Call("querySelectorAll", ".mobile-lang-select")
	length = nodeList.Get("length").Int()
	for i := 0; i < length; i++ {
		link := nodeList.Call("item", i)
		link.Call("addEventListener", "click", func(event *js.Object) {
			// prevent follow link to #
			event.Call("preventDefault")

			locale := link.Get("dataset").Get("lang").String()
			jsgettext.Translate(locale)

			// close toggle window on mobile device
			punch.Set("checked", true)
		})
	}
}