Skip to content

Commit

Permalink
Add ability to change browser title
Browse files Browse the repository at this point in the history
  • Loading branch information
fedegratti committed Apr 26, 2022
1 parent 5bd56b1 commit df3b57c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.6.1
v6.7.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 33 additions & 0 deletions src/view_components/ViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ViewManager
this.transition_handler = new ViewStateTransitionHandler(this.transition_table);

this.view_change_subscribers = [];

this.browser_title_suffix = '';
}

update()
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -135,13 +143,38 @@ 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++)
{
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();

0 comments on commit df3b57c

Please sign in to comment.