Skip to content

Commit

Permalink
UI-2369: Add documentation for monster.ui.loadTab() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
joristirado committed Nov 18, 2016
1 parent 06dff08 commit 88e0d55
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
81 changes: 81 additions & 0 deletions docs/monster/ui/loadTab().md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# [monster][monster].[ui][ui].loadTab()
The `monster.ui.loadTab()` method programmatically loads the navbar tab corresponding to the tab ID passed as argument.

* [Syntax](#syntax)
* [Parameters](#parameters)
* [Description](#description)
* [Examples](#examples)

### Syntax
```javascript
monster.ui.loadTab(thisArg, id);
```

### Parameters
* `thisArg` (mandatory)

Type: [Object][object_literal]

The context of the app invoking the helper.

* `id` (mandatory)

Type: [String][string_literal]

Unique ID referencing a navbar tab of the app.

### Description
This helper is used to virtually trigger a click on a navbar tab so that the callback related to that tab is called. It is powerful in a sense that all the navbar animations are performed accordingly and also take into account if that tab has a `onClick` bypass callback.

The utility of this helper can be found when a user performs an action that need to load content located in another tab.

### Examples
* Load the content of another tab

Specify an `id` when declaring the tabs in render() function
```javascript
var self = this;

monster.ui.generateLayout(self, {
menus: [
{
tabs: [
{
id: 'devices',
title: 'List Devices',
callback: self.renderListDevices
},
{
id: 'users',
title: 'List Users',
callback: self.renderListUsers
}
]
}
]
});
```

Call helper to load another tab
```javascript
{
renderListDevices: function(args) {
var self = this;

monster.ui.loadTab(self, 'users');
},
renderListUsers: function(args) {
var self = this;

monster.ui.loadTab(self, 'devices');
}
}
```

This example is just an easy way to show how the helper works and does not have a real purpose.

[monster]: ../../monster.md
[ui]: ../ui.md

[string_literal]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#String_literals
[object_literal]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#Object_literals
5 changes: 5 additions & 0 deletions src/js/lib/monster.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,11 @@ define(function(require){
callDefaultTabCallback();
},

/**
* Programmatically loads the navbar tab corresponding to the tab ID passed as argument
* @param {Object} thisArg Context of the app
* @param {String} id Unique ID to identify the tab
*/
loadTab: function(thisArg, id) {
var self = this,
$tab = $('.navbar-menu-item-link[data-id="' + id + '"]');
Expand Down

0 comments on commit 88e0d55

Please sign in to comment.