diff --git a/.version b/.version index ecb8b9a..3f3ac79 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v6.6.1 +v6.7.0 diff --git a/package.json b/package.json index 69a6be0..0cdd84c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ohzi-core", - "version": "6.6.1", + "version": "6.7.0", "description": "OHZI Core Library", "source": "src/index.js", "module": "build/index.module.js", diff --git a/src/view_components/ViewManager.js b/src/view_components/ViewManager.js index dca9012..be934e3 100644 --- a/src/view_components/ViewManager.js +++ b/src/view_components/ViewManager.js @@ -11,6 +11,8 @@ class ViewManager this.transition_handler = new ViewStateTransitionHandler(this.transition_table); this.view_change_subscribers = []; + + this.browser_title_suffix = ''; } update() @@ -28,6 +30,7 @@ class ViewManager if (change_url) { this.__change_browser_url(v.url); + this.__change_browser_title(v.url); } this.notify_view_change(view_name); @@ -81,6 +84,11 @@ class ViewManager this.transition_handler.set_state(view); } + set_browser_title_suffix(title_suffix) + { + this.browser_title_suffix = title_suffix; + } + get_current_view() { return this.transition_handler.current_state; @@ -135,6 +143,13 @@ class ViewManager window.history.pushState('', '', url); } + __change_browser_title(name) + { + const title = this.__capitalize(name); + + document.title = title ? `${title} | ${this.browser_title_suffix}` : this.browser_title_suffix; + } + __set_views_opacities() { for (let i = 0; i < this.views.length; i++) @@ -142,6 +157,24 @@ class ViewManager this.views[i].set_opacity(this.transition_handler.current_state_data); } } + + __capitalize(string) + { + let aux_string = string.toUpperCase().replace('/', ''); + aux_string = this.__snake_to_whitespace(aux_string); + + return aux_string; + } + + __snake_to_whitespace(string) + { + return string.replace( + /([-_][A-Z])/g, + (group) => group + .replace('-', ' ') + .replace('_', ' ') + ); + } } export default new ViewManager();