1
+ ( function ( factory ) {
2
+ if ( typeof define === 'function' && define . amd ) {
3
+ define ( [ 'jquery' , 'sammy' ] , factory ) ;
4
+ } else {
5
+ ( window . Sammy = window . Sammy || { } ) . Title = factory ( window . jQuery , window . Sammy ) ;
6
+ }
7
+ } ( function ( $ , Sammy ) {
8
+
9
+ // Sammy.Title is a very simple plugin to easily set the document's title.
10
+ // It supplies a helper for setting the title (`title()`) within routes,
11
+ // and an app level method for setting the global title (`setTitle()`)
12
+ Sammy . Title = function ( ) {
13
+
14
+ // setTitle allows setting a global title or a function that modifies the
15
+ // title for each route/page.
16
+ //
17
+ // ### Example
18
+ //
19
+ // // setting a title prefix
20
+ // $.sammy(function() {
21
+ //
22
+ // this.setTitle('My App -');
23
+ //
24
+ // this.get('#/', function() {
25
+ // this.title('Home'); // document's title == "My App - Home"
26
+ // });
27
+ // });
28
+ //
29
+ // // setting a title with a function
30
+ // $.sammy(function() {
31
+ //
32
+ // this.setTitle(function(title) {
33
+ // return [title, " /// My App"].join('');
34
+ // });
35
+ //
36
+ // this.get('#/', function() {
37
+ // this.title('Home'); // document's title == "Home /// My App";
38
+ // });
39
+ // });
40
+ //
41
+ this . setTitle = function ( title ) {
42
+ if ( ! $ . isFunction ( title ) ) {
43
+ this . title_function = function ( additional_title ) {
44
+ return [ title , additional_title ] . join ( ' ' ) ;
45
+ }
46
+ } else {
47
+ this . title_function = title ;
48
+ }
49
+ } ;
50
+
51
+ // *Helper* title() sets the document title, passing it through the function
52
+ // defined by setTitle() if set.
53
+ this . helper ( 'title' , function ( ) {
54
+ var new_title = $ . makeArray ( arguments ) . join ( ' ' ) ;
55
+ if ( this . app . title_function ) {
56
+ new_title = this . app . title_function ( new_title ) ;
57
+ }
58
+ document . title = new_title ;
59
+ } ) ;
60
+
61
+ } ;
62
+
63
+ return Sammy . Title ;
64
+
65
+ } ) ) ;
66
+
1
67
dispatcher_add ( function ( sammy ) {
2
68
function path ( p , r , t ) {
3
69
sammy . get ( p , function ( ) {
4
70
render ( r , t , p ) ;
5
71
} ) ;
6
72
}
7
73
sammy . get ( '#/' , function ( ) {
74
+ this . title ( 'Overview' ) ;
8
75
var reqs = { 'overview' : { path : '/overview' ,
9
76
options : { ranges : [ 'lengths-over' ,
10
77
'msg-rates-over' ] } } ,
@@ -15,6 +82,7 @@ dispatcher_add(function(sammy) {
15
82
render ( reqs , 'overview' , '#/' ) ;
16
83
} ) ;
17
84
sammy . get ( '#/' , function ( ) {
85
+ this . title ( 'Overview' ) ;
18
86
var reqs = { 'overview' : { path : '/overview' ,
19
87
options : { ranges : [ 'lengths-over' ,
20
88
'msg-rates-over' ] } } ,
@@ -34,6 +102,7 @@ dispatcher_add(function(sammy) {
34
102
} ) ;
35
103
36
104
sammy . get ( '#/nodes/:name' , function ( ) {
105
+ this . title ( 'Node ' + this . params [ 'name' ] ) ;
37
106
var name = esc ( this . params [ 'name' ] ) ;
38
107
render ( { 'node' : { path : '/nodes/' + name ,
39
108
options : { ranges : [ 'node-stats' ] } } } ,
@@ -81,10 +150,12 @@ dispatcher_add(function(sammy) {
81
150
options :{ ranges :[ 'data-rates-ch' , 'msg-rates-ch' ] } } } ,
82
151
'channel' , '#/channels' ) ;
83
152
} ) ;
84
- sammy . get ( '#/exchanges' , function ( ) {
153
+ sammy . get ( '#/exchanges' , function ( ) {
154
+ this . title ( 'Exchanges' ) ;
85
155
renderExchanges ( ) ;
86
156
} ) ;
87
157
sammy . get ( '#/exchanges/:vhost/:name' , function ( ) {
158
+ this . title ( 'Exchange ' + esc ( this . params [ 'vhost' ] ) + '/' + this . params [ 'name' ] ) ;
88
159
var path = '/exchanges/' + esc ( this . params [ 'vhost' ] ) + '/' + esc ( this . params [ 'name' ] ) ;
89
160
render ( { 'exchange' : { path : path ,
90
161
options : { ranges :[ 'msg-rates-x' ] } } ,
@@ -108,12 +179,14 @@ dispatcher_add(function(sammy) {
108
179
} ) ;
109
180
110
181
sammy . get ( '#/queues' , function ( ) {
182
+ this . title ( 'Queues' ) ;
111
183
renderQueues ( ) ;
112
184
} ) ;
113
185
114
186
sammy . get ( '#/queues/:vhost/:name' , function ( ) {
115
187
var vhost = this . params [ 'vhost' ] ;
116
188
var queue = this . params [ 'name' ] ;
189
+ this . title ( 'Queue ' + esc ( vhost ) + '/' + queue ) ;
117
190
var path = '/queues/' + esc ( vhost ) + '/' + esc ( queue ) ;
118
191
var requests = { 'queue' : { path : path ,
119
192
options : { ranges :[ 'lengths-q' , 'msg-rates-q' , 'data-rates-q' ] } } ,
@@ -198,7 +271,8 @@ dispatcher_add(function(sammy) {
198
271
} ) ;
199
272
200
273
sammy . get ( '#/users' , function ( ) {
201
- renderUsers ( ) ;
274
+ this . title ( 'Users' ) ;
275
+ renderUsers ( ) ;
202
276
} ) ;
203
277
sammy . get ( '#/users/:id' , function ( ) {
204
278
var vhosts = JSON . parse ( sync_get ( '/vhosts' ) ) ;
0 commit comments