Commit f561d73e02b64d65229beabcc986a67ebadfe05d
1 parent
88f94323
Exists in
master
and in
7 other branches
Proposta para issue #217
Showing
1 changed file
with
20 additions
and
1 deletions
Show diff stats
js/main.js
| ... | ... | @@ -300,6 +300,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 300 | 300 | this.navigateTo(hash); |
| 301 | 301 | }, |
| 302 | 302 | navigateTo: function(hash){ |
| 303 | + var scrollTop = 0; | |
| 303 | 304 | var regexProposals = /#\/programas/; |
| 304 | 305 | var regexCategory = /#\/temas/; |
| 305 | 306 | var regexHideBarra = /barra=false$/; |
| ... | ... | @@ -323,6 +324,12 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 323 | 324 | // go to proposal |
| 324 | 325 | var proposalId = parts[2]; |
| 325 | 326 | this.navigateToProposal(proposalId); |
| 327 | + | |
| 328 | + var $proposal = $('#proposal-item-' + proposalId); | |
| 329 | + var offset = $proposal.offset(); | |
| 330 | + if(offset){ | |
| 331 | + scrollTop = offset.top; | |
| 332 | + } | |
| 326 | 333 | } |
| 327 | 334 | |
| 328 | 335 | if( isCategory ){ |
| ... | ... | @@ -330,15 +337,27 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 330 | 337 | // go to category |
| 331 | 338 | var categoryId = parts[3]; |
| 332 | 339 | this.navigateToCategory(categoryId); |
| 340 | + | |
| 341 | + var $category = $('#proposal-item-' + categoryId); | |
| 342 | + var offset = $category.offset(); | |
| 343 | + if(offset){ | |
| 344 | + scrollTop = offset.top; | |
| 345 | + } | |
| 333 | 346 | } |
| 334 | 347 | |
| 335 | 348 | // default |
| 336 | 349 | if( !isProposal && !isCategory ){ |
| 337 | 350 | // show the 'index' -> category tab |
| 338 | 351 | this.display_category_tab(); |
| 352 | + | |
| 353 | + var $nav = $('nav[role="tabpanel"]'); | |
| 354 | + var offset = $nav.offset(); | |
| 355 | + if(offset){ | |
| 356 | + scrollTop = offset.top; | |
| 357 | + } | |
| 339 | 358 | } |
| 340 | 359 | |
| 341 | - $('html, body').animate({ scrollTop: 0 }, 'fast'); | |
| 360 | + $('html, body').animate({ scrollTop: scrollTop }, 'fast'); | |
| 342 | 361 | }, |
| 343 | 362 | navigateToProposal: function(proposalId){ |
| 344 | 363 | var regexSubpages = /sobre-o-programa$/; | ... | ... |