Documentation ¶
Overview ¶
Package suggest provides input suggestion menu feature for frontend. This is similar to Autocomplete feature of Buefy (https://buefy.org/). The code of this library is written in Go and must be compiled to JavaScript via GopherJS. The BindSuggest method is initialization function of the input suggest. For simple application, using this method once in your application initialization code should be enough and it will run automatically. If you need to control the behavior of the suggest menu during the runtime of your application, use UpdateSuggestion or HideSuggestion methods.
Index ¶
- Constants
- func HideSuggestion()
- func IsShowSuggestMenu() bool
- func OnHideSuggestMenu(handler func())
- func OnHighlightSelectedWord(handler func(string))
- func OnUpdateSuggestMenu(handler func(string))
- func UpdateSuggestion()
- type SuggestMenuStateMachine
- func (s *SuggestMenuStateMachine) GetWord() string
- func (s *SuggestMenuStateMachine) HandleArrowDown()
- func (s *SuggestMenuStateMachine) HandleArrowUp()
- func (s *SuggestMenuStateMachine) HandleESC()
- func (s *SuggestMenuStateMachine) HideSuggestMenu()
- func (s *SuggestMenuStateMachine) HighlightSelectedWord(index int)
- func (s *SuggestMenuStateMachine) SetWord(word string)
- func (s *SuggestMenuStateMachine) ShowSuggestMenu()
- func (s *SuggestMenuStateMachine) UnhighlightSelectedWord(index int)
- func (s *SuggestMenuStateMachine) UpdateSuggestMenu(word string)
Constants ¶
const ( TAB = 9 RETURN = 13 ESC = 27 LEFT = 37 UP = 38 RIGHT = 39 DOWN = 40 )
Variables ¶
This section is empty.
Functions ¶
func IsShowSuggestMenu ¶
func IsShowSuggestMenu() bool
IsShowSuggestMenu reports if the suggest menu is visible now.
func OnHideSuggestMenu ¶
func OnHideSuggestMenu(handler func())
OnHideSuggestMenu registers an event handler when suggest menu is being hidden.
func OnHighlightSelectedWord ¶
func OnHighlightSelectedWord(handler func(string))
OnHighlightSelectedWord registers an event handler of which the argument is the selected word.
func OnUpdateSuggestMenu ¶
func OnUpdateSuggestMenu(handler func(string))
OnUpdateSuggestMenu registers an event handler of which the argument is the selected word.
func UpdateSuggestion ¶
func UpdateSuggestion()
UpdateSuggestion will read the value of input element and update suggest menu accordingly.
Types ¶
type SuggestMenuStateMachine ¶
type SuggestMenuStateMachine struct { Input *Object SuggestMenu *Object FuncSugguestWords func(string) []string CurrentSelectedWordIndex int IsShowSuggestMenu bool SuggestedWordsDivs []*Object OriginalWord string SuggestedWords []string HighlightSelectedWordHandler []func(string) UpdateSuggestMenuHandler []func(string) HideSuggestMenuHandler []func() }
func BindSuggest ¶
func BindSuggest(id string, fnSugguestWords func(string) []string) *SuggestMenuStateMachine
BindSuggest is the initialization function for the input suggest feature. The first argument is the id of the input element. The second argument is a function implemented by you. Given a string, the function will return possible suggest strings for users to choose.
func NewSuggestMenuStateMachine ¶
func NewSuggestMenuStateMachine(input, sm *Object, fnSugguestWords func(string) []string) *SuggestMenuStateMachine
func (*SuggestMenuStateMachine) GetWord ¶
func (s *SuggestMenuStateMachine) GetWord() string
func (*SuggestMenuStateMachine) HandleArrowDown ¶
func (s *SuggestMenuStateMachine) HandleArrowDown()
func (*SuggestMenuStateMachine) HandleArrowUp ¶
func (s *SuggestMenuStateMachine) HandleArrowUp()
func (*SuggestMenuStateMachine) HandleESC ¶
func (s *SuggestMenuStateMachine) HandleESC()
func (*SuggestMenuStateMachine) HideSuggestMenu ¶
func (s *SuggestMenuStateMachine) HideSuggestMenu()
func (*SuggestMenuStateMachine) HighlightSelectedWord ¶
func (s *SuggestMenuStateMachine) HighlightSelectedWord(index int)
func (*SuggestMenuStateMachine) SetWord ¶
func (s *SuggestMenuStateMachine) SetWord(word string)
func (*SuggestMenuStateMachine) ShowSuggestMenu ¶
func (s *SuggestMenuStateMachine) ShowSuggestMenu()
func (*SuggestMenuStateMachine) UnhighlightSelectedWord ¶
func (s *SuggestMenuStateMachine) UnhighlightSelectedWord(index int)
func (*SuggestMenuStateMachine) UpdateSuggestMenu ¶
func (s *SuggestMenuStateMachine) UpdateSuggestMenu(word string)