diff --git a/README-ru.md b/README-ru.md index 0bbc0d9..693e8d6 100644 --- a/README-ru.md +++ b/README-ru.md @@ -4233,6 +4233,10 @@ Safari и Firefox. * RootView() View - возвращает корневой View сессии +* SetTitle(title string) - устанавливает текст заголовка окна/закладки браузера. + +* SetTitleColor(color Color) устанавливает цвет панели навигации браузера. Поддерживается только в Safari и Chrome для Android. + * Get(viewID, tag string) interface{} - возвращает значение свойства View с именем tag. Эквивалентно rui.Get(session.RootView(), viewID, tag) diff --git a/README.md b/README.md index 7aa9876..f98ff20 100644 --- a/README.md +++ b/README.md @@ -4198,6 +4198,10 @@ Returns false if no topic with this name was found. Themes named "" are the defa * RootView() View returns the root View of the session +* SetTitle(title string) sets the text of the browser title/tab + +* SetTitleColor(color Color) sets the color of the browser navigation bar. Supported only in Safari and Chrome for android + * Get(viewID, tag string) interface{} returns the value of the View property named tag. Equivalent to rui.Get(session.RootView(), viewID, tag) diff --git a/app_scripts.js b/app_scripts.js index d21cff0..40c41fd 100644 --- a/app_scripts.js +++ b/app_scripts.js @@ -1336,3 +1336,19 @@ function startDowndload(url, filename) { element.click(); } } + +function setTitleColor(color) { + var metas = document.getElementsByTagName('meta'); + if (metas) { + var item = metas.namedItem('theme-color'); + if (item) { + item.setAttribute('content', color) + return + } + } + + var meta = document.createElement('meta'); + meta.setAttribute('name', 'theme-color'); + meta.setAttribute('content', color); + document.getElementsByTagName('head')[0].appendChild(meta); +} \ No newline at end of file diff --git a/demo/main.go b/demo/main.go index 6f0488f..22cf9fe 100644 --- a/demo/main.go +++ b/demo/main.go @@ -113,6 +113,9 @@ func (demo *demoSession) CreateRootView(session rui.Session) rui.View { rui.Set(demo.rootView, "rootTitleButton", rui.ClickEvent, demo.clickMenuButton) demo.showPage(0) + if color, ok := rui.StringToColor("#ffc0ded9"); ok { + session.SetTitleColor(color) + } return demo.rootView } @@ -147,6 +150,7 @@ func (demo *demoSession) showPage(index int) { stackLayout.MoveToFront(demo.pages[index].view) } rui.Set(demo.rootView, "rootTitleText", rui.Text, demo.pages[index].title) + demo.rootView.Session().SetTitle(demo.pages[index].title) } // TODO } diff --git a/session.go b/session.go index 8517a8e..e015baf 100644 --- a/session.go +++ b/session.go @@ -40,9 +40,15 @@ type Session interface { // GetString returns the text for the current language GetString(tag string) (string, bool) + // Content returns the SessionContent of session Content() SessionContent setContent(content SessionContent, self Session) bool + // SetTitle sets the text of the browser title/tab + SetTitle(title string) + // SetTitleColor sets the color of the browser navigation bar. Supported only in Safari and Chrome for android + SetTitleColor(color Color) + // RootView returns the root view of the session RootView() View // Get returns a value of the view (with id defined by the first argument) property with name defined by the second argument. @@ -53,7 +59,9 @@ type Session interface { // a description of the error is written to the log Set(viewID, tag string, value interface{}) bool + // DownloadFile downloads (saves) on the client side the file located at the specified path on the server. DownloadFile(path string) + //DownloadFileData downloads (saves) on the client side a file with a specified name and specified content. DownloadFileData(filename string, data []byte) registerAnimation(props []AnimatedProperty) string @@ -406,3 +414,12 @@ func (session *sessionData) handleViewEvent(command string, data DataObject) { ErrorLog(`"id" property not found. Event: ` + command) } } + +func (session *sessionData) SetTitle(title string) { + title, _ = session.GetString(title) + session.runScript(`document.title = "` + title + `";`) +} + +func (session *sessionData) SetTitleColor(color Color) { + session.runScript(`setTitleColor("` + color.cssString() + `");`) +}