@@ -672,54 +672,36 @@ $(document).ready(function() {
672
672
// ^^^^^^^^^^^^^^^^^^ END stuff for making pretty dates ^^^^^^^^^^^^^^^^^^^
673
673
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
674
674
675
- var sequence_url = $ ( " #sequence_footer .sequence_details_url" ) . filter ( " :last" ) . attr ( 'href' ) ;
676
- if ( sequence_url ) {
675
+ var sequence_url = $ ( ' #sequence_footer .sequence_details_url' ) . filter ( ' :last' ) . attr ( 'href' ) ;
676
+ if ( sequence_url ) {
677
677
$ . ajaxJSON ( sequence_url , 'GET' , { } , function ( data ) {
678
- if ( data . current_item ) {
679
- $ ( "#sequence_details .current" ) . fillTemplateData ( { data : data . current_item . content_tag } ) ;
680
- if ( data . previous_item || data . previous_module ) {
681
- var tag = data . previous_item && data . previous_item . content_tag ;
682
- var $prev = $ ( "#sequence_footer .prev" ) ;
683
- tag = tag || ( data . previous_module && data . previous_module . context_module ) ;
684
- if ( ! data . previous_item ) {
685
- tag . title = tag . title || tag . name ;
686
- tag . text = "Previous Module" ;
687
- $prev . addClass ( 'module_button' ) ;
688
- }
689
- $prev . fillTemplateData ( {
690
- data : tag
691
- } ) ;
692
- if ( data . previous_item ) {
693
- $prev . attr ( 'href' , $ . replaceTags ( $ ( "#sequence_footer .module_item_url" ) . attr ( 'href' ) , 'id' , tag . id ) ) ;
694
- } else {
695
- $prev . attr ( 'href' , $ . replaceTags ( $ ( "#sequence_footer .module_url" ) . attr ( 'href' ) , 'id' , tag . id ) + "/items/last" ) ;
696
- }
697
- } else {
698
- $ ( "#sequence_footer .prev" ) . hide ( ) ;
699
- }
700
- if ( data . next_item || data . next_module ) {
701
- var tag = data . next_item && data . next_item . content_tag ;
702
- var $next = $ ( "#sequence_footer .next" )
703
- tag = tag || ( data . next_module && data . next_module . context_module ) ;
704
- if ( ! data . next_item ) {
705
- tag . title = tag . title || tag . name ;
706
- tag . text = "Next Module" ;
707
- $next . addClass ( 'module_button' ) ;
708
- }
709
- $next . fillTemplateData ( {
710
- data : tag
711
- } ) ;
712
- if ( data . next_item ) {
713
- $next . attr ( 'href' , $ . replaceTags ( $ ( "#sequence_footer .module_item_url" ) . attr ( 'href' ) , 'id' , tag . id ) ) ;
678
+ var $sequence_footer = $ ( '#sequence_footer' ) ;
679
+ if ( data . current_item ) {
680
+ $ ( '#sequence_details .current' ) . fillTemplateData ( { data : data . current_item . content_tag } ) ;
681
+ $ . each ( { previous :'.prev' , next :'.next' } , function ( label , cssClass ) {
682
+ var $link = $sequence_footer . find ( cssClass ) ;
683
+ if ( data [ label + '_item' ] || data [ label + '_module' ] ) {
684
+ var tag = ( data [ label + '_item' ] && data [ label + '_item' ] . content_tag ) ||
685
+ ( data [ label + '_module' ] && data [ label + '_module' ] . context_module ) ;
686
+
687
+ if ( ! data [ label + '_item' ] ) {
688
+ tag . title = tag . title || tag . name ;
689
+ tag . text = $ . capitalize ( label ) + ' Module' ;
690
+ $link . addClass ( 'module_button' ) ;
691
+ }
692
+ $link . fillTemplateData ( { data : tag } ) ;
693
+ if ( data . previous_item ) {
694
+ $link . attr ( 'href' , $ . replaceTags ( $sequence_footer . find ( '.module_item_url' ) . attr ( 'href' ) , 'id' , tag . id ) ) ;
695
+ } else {
696
+ $link . attr ( 'href' , $ . replaceTags ( $sequence_footer . find ( '.module_url' ) . attr ( 'href' ) , 'id' , tag . id ) + '/items/' + ( label === 'previous' ? 'last' : 'first' ) ) ;
697
+ }
714
698
} else {
715
- $next . attr ( 'href' , $ . replaceTags ( $ ( "#sequence_footer .module_url" ) . attr ( 'href' ) , 'id' , tag . id ) + "/items/first" ) ;
699
+ $link . hide ( ) ;
716
700
}
717
- } else {
718
- $ ( "#sequence_footer .next" ) . hide ( ) ;
719
- }
720
- $ ( "#sequence_footer" ) . show ( ) ;
701
+ } ) ;
702
+ $sequence_footer . show ( ) ;
721
703
}
722
- } , function ( ) { } ) ;
704
+ } ) ;
723
705
}
724
706
725
707
$ ( ".module_legend_link" ) . click ( function ( event ) {
@@ -826,7 +808,7 @@ $(document).ready(function() {
826
808
remove ( url ) ;
827
809
}
828
810
}
829
- } )
811
+ } ) ;
830
812
} else {
831
813
remove ( url + "?permanent=1" ) ;
832
814
}
0 commit comments