Skip to content
Browse files

Version switcher is now populated from /versions.json

  • Loading branch information...
1 parent 69671a6 commit 6ac3a11d7089f468d19376c3defdb0d05f11eb90 @eskatos eskatos committed Mar 24, 2013
Showing with 142 additions and 175 deletions.
  1. +45 −59 2.0-RC1/js/progressive-enhancement.js
  2. +45 −57 develop/js/progressive-enhancement.js
  3. +45 −59 latest/js/progressive-enhancement.js
  4. +7 −0 versions.json
View
104 2.0-RC1/js/progressive-enhancement.js
@@ -48,62 +48,45 @@ $( document ).ready( function($){
$("a.ulink[href^='https:']").attr('target','_blank');
// Add links to different versions
- var versions =
+ $.getJSON( "../versions.json", function( versions )
{
- '2.0-RC1':
+ // alert( JSON.stringify( versions ) );
+ var currentPathFragment = window.location.href.substring( 0, window.location.href.lastIndexOf( '/' ) );
+ currentPathFragment = currentPathFragment.substring( currentPathFragment.lastIndexOf( '/' ) + 1 );
+ var currentVersion = Object.keys( versions ).filter( function( key ) { return versions[ key ] === currentPathFragment } )[ 0 ];
+ // alert( "Current version is " + currentVersion + "\nCurrent path fragment is: " + currentPathFragment );
+ if( currentVersion )
{
- 'url': 'http://qi4j.org/2.0-RC1',
- 'relpath': '../2.0-RC1'
- },
- 'develop':
- {
- 'url': 'http://qi4j.org/develop',
- 'relpath': '../develop'
- },
- 'latest':
- {
- 'url': 'http://qi4j.org/latest',
- 'relpath': '../latest'
- },
- '<=1.4.x':
- {
- 'url': 'http://qi4j.org/1.4',
- 'relpath': '../1.4'
- }
- };
- function endsWith(str, suffix) {
- return str.indexOf(suffix, str.length - suffix.length) !== -1;
- }
- var selected = "latest";
- var stripedHref = window.location.href.substring( 0, window.location.href.lastIndexOf('/') );
- if ( endsWith( stripedHref, 'develop' ) )
- selected = "develop";
- else if ( endsWith( stripedHref, 'latest' ) )
- selected = "latest";
- else if ( endsWith( stripedHref, '1.4' ) )
- selected = "<=1.4.x";
- else if ( endsWith( stripedHref, '2.0-RC1' ) )
- selected = "2.0-RC1";
- // --
- var switcher_html ='<p style="margin-top:2em; text-align: center"><select style="font-size: 0.5em">';
- var ifselect = function( candidate ) {
- return candidate == selected ? "selected=\"selected\"" : "";
- }
- for( var version in versions )
- {
- switcher_html += '<option value="' + version + '" ' + ifselect( version ) + '>' + version + '</option>';
- }
- switcher_html += '</select></p>' ;
- $( "div.logo" ).append( switcher_html );
- $( "div.logo select" ).change( function()
- {
- if( window.location.hostname == "qi4j.org" || window.location.hostname == "www.qi4j.org" )
- { // Loaded from qi4j.org
- window.location = versions[ $( this ).val() ].relpath;
+ var switcher_html ='<p style="margin-top:2em; text-align: center"><select style="font-size: 0.5em">';
+ var ifselect = function( candidate )
+ {
+ return candidate == currentVersion ? "selected=\"selected\"" : "";
+ }
+ $.each( versions, function( displayName, pathFragment )
+ {
+ switcher_html += '<option value="' + displayName + '" ' + ifselect( displayName ) + '>' + displayName + '</option>';
+ } );
+ switcher_html += '</select></p>';
+ $( "div.logo" ).append( switcher_html );
+ var toURL = function( displayName )
+ {
+ if( window.location.hostname == "qi4j.org" || window.location.hostname == "www.qi4j.org" )
+ {
+ return "../" + versions[ displayName ];
+ }
+ else
+ {
+ return "http://qi4j.org/" + versions[ displayName ];
+ }
+ }
+ $( "div.logo select" ).change( function()
+ {
+ window.location = toURL( $( this ).val() );
+ } );
}
else
- { // Loaded from elsewhere
- window.location = versions[ $( this ).val() ].url;
+ {
+ console.log( "Documentation loaded locally? No version switcher" );
}
} );
@@ -126,13 +109,16 @@ $( document ).ready( function($){
// Section specific enhancements
var $section = $( 'body > div.section' );
- var section_title = $section.attr( 'title' ).trim();
- switch( section_title ) {
- case "Glossary":
- glossary( $section );
- break;
- default:
- break;
+ if( $section.attr( 'title' ) )
+ {
+ var section_title = $section.attr( 'title' ).trim();
+ switch( section_title ) {
+ case "Glossary":
+ glossary( $section );
+ break;
+ default:
+ break;
+ }
}
} );
View
102 develop/js/progressive-enhancement.js
@@ -48,60 +48,45 @@ $( document ).ready( function($){
$("a.ulink[href^='https:']").attr('target','_blank');
// Add links to different versions
- var versions =
+ $.getJSON( "../versions.json", function( versions )
{
- 'develop':
+ // alert( JSON.stringify( versions ) );
+ var currentPathFragment = window.location.href.substring( 0, window.location.href.lastIndexOf( '/' ) );
+ currentPathFragment = currentPathFragment.substring( currentPathFragment.lastIndexOf( '/' ) + 1 );
+ var currentVersion = Object.keys( versions ).filter( function( key ) { return versions[ key ] === currentPathFragment } )[ 0 ];
+ // alert( "Current version is " + currentVersion + "\nCurrent path fragment is: " + currentPathFragment );
+ if( currentVersion )
{
- 'url': 'http://qi4j.org/develop',
- 'relpath': '../develop'
- },
- 'latest':
- {
- 'url': 'http://qi4j.org/latest',
- 'relpath': '../latest'
- },
- '2.0-RC1':
- {
- 'url': 'http://qi4j.org/2.0-RC1',
- 'relpath': '../2.0-RC1'
- },
- '<=1.4.x':
- {
- 'url': 'http://qi4j.org/1.4',
- 'relpath': '../1.4'
- }
- };
- function endsWith(str, suffix) {
- return str.indexOf(suffix, str.length - suffix.length) !== -1;
- }
- var selected = "latest";
- var stripedHref = window.location.href.substring( 0, window.location.href.lastIndexOf('/') );
- if ( endsWith( stripedHref, 'develop' ) )
- selected = "develop";
- else if ( endsWith( stripedHref, 'latest' ) )
- selected = "latest";
- else if ( endsWith( stripedHref, '1.4' ) )
- selected = "<=1.4.x";
- // --
- var switcher_html ='<p style="margin-top:2em; text-align: center"><select style="font-size: 0.5em">';
- var ifselect = function( candidate ) {
- return candidate == selected ? "selected=\"selected\"" : "";
- }
- for( var version in versions )
- {
- switcher_html += '<option value="' + version + '" ' + ifselect( version ) + '>' + version + '</option>';
- }
- switcher_html += '</select></p>' ;
- $( "div.logo" ).append( switcher_html );
- $( "div.logo select" ).change( function()
- {
- if( window.location.hostname == "qi4j.org" || window.location.hostname == "www.qi4j.org" )
- { // Loaded from qi4j.org
- window.location = versions[ $( this ).val() ].relpath;
+ var switcher_html ='<p style="margin-top:2em; text-align: center"><select style="font-size: 0.5em">';
+ var ifselect = function( candidate )
+ {
+ return candidate == currentVersion ? "selected=\"selected\"" : "";
+ }
+ $.each( versions, function( displayName, pathFragment )
+ {
+ switcher_html += '<option value="' + displayName + '" ' + ifselect( displayName ) + '>' + displayName + '</option>';
+ } );
+ switcher_html += '</select></p>';
+ $( "div.logo" ).append( switcher_html );
+ var toURL = function( displayName )
+ {
+ if( window.location.hostname == "qi4j.org" || window.location.hostname == "www.qi4j.org" )
+ {
+ return "../" + versions[ displayName ];
+ }
+ else
+ {
+ return "http://qi4j.org/" + versions[ displayName ];
+ }
+ }
+ $( "div.logo select" ).change( function()
+ {
+ window.location = toURL( $( this ).val() );
+ } );
}
else
- { // Loaded from elsewhere
- window.location = versions[ $( this ).val() ].url;
+ {
+ console.log( "Documentation loaded locally? No version switcher" );
}
} );
@@ -124,13 +109,16 @@ $( document ).ready( function($){
// Section specific enhancements
var $section = $( 'body > div.section' );
- var section_title = $section.attr( 'title' ).trim();
- switch( section_title ) {
- case "Glossary":
- glossary( $section );
- break;
- default:
- break;
+ if( $section.attr( 'title' ) )
+ {
+ var section_title = $section.attr( 'title' ).trim();
+ switch( section_title ) {
+ case "Glossary":
+ glossary( $section );
+ break;
+ default:
+ break;
+ }
}
} );
View
104 latest/js/progressive-enhancement.js
@@ -48,62 +48,45 @@ $( document ).ready( function($){
$("a.ulink[href^='https:']").attr('target','_blank');
// Add links to different versions
- var versions =
+ $.getJSON( "../versions.json", function( versions )
{
- 'latest':
+ // alert( JSON.stringify( versions ) );
+ var currentPathFragment = window.location.href.substring( 0, window.location.href.lastIndexOf( '/' ) );
+ currentPathFragment = currentPathFragment.substring( currentPathFragment.lastIndexOf( '/' ) + 1 );
+ var currentVersion = Object.keys( versions ).filter( function( key ) { return versions[ key ] === currentPathFragment } )[ 0 ];
+ // alert( "Current version is " + currentVersion + "\nCurrent path fragment is: " + currentPathFragment );
+ if( currentVersion )
{
- 'url': 'http://qi4j.org/latest',
- 'relpath': '../latest'
- },
- '2.0-RC1':
- {
- 'url': 'http://qi4j.org/2.0-RC1',
- 'relpath': '../2.0-RC1'
- },
- 'develop':
- {
- 'url': 'http://qi4j.org/develop',
- 'relpath': '../develop'
- },
- '<=1.4.x':
- {
- 'url': 'http://qi4j.org/1.4',
- 'relpath': '../1.4'
- }
- };
- function endsWith(str, suffix) {
- return str.indexOf(suffix, str.length - suffix.length) !== -1;
- }
- var selected = "latest";
- var stripedHref = window.location.href.substring( 0, window.location.href.lastIndexOf('/') );
- if ( endsWith( stripedHref, 'develop' ) )
- selected = "develop";
- else if ( endsWith( stripedHref, 'latest' ) )
- selected = "latest";
- else if ( endsWith( stripedHref, '2.0-RC1' ) )
- selected = "2.0-RC1";
- else if ( endsWith( stripedHref, '1.4' ) )
- selected = "<=1.4.x";
- // --
- var switcher_html ='<p style="margin-top:2em; text-align: center"><select style="font-size: 0.5em">';
- var ifselect = function( candidate ) {
- return candidate == selected ? "selected=\"selected\"" : "";
- }
- for( var version in versions )
- {
- switcher_html += '<option value="' + version + '" ' + ifselect( version ) + '>' + version + '</option>';
- }
- switcher_html += '</select></p>' ;
- $( "div.logo" ).append( switcher_html );
- $( "div.logo select" ).change( function()
- {
- if( window.location.hostname == "qi4j.org" || window.location.hostname == "www.qi4j.org" )
- { // Loaded from qi4j.org
- window.location = versions[ $( this ).val() ].relpath;
+ var switcher_html ='<p style="margin-top:2em; text-align: center"><select style="font-size: 0.5em">';
+ var ifselect = function( candidate )
+ {
+ return candidate == currentVersion ? "selected=\"selected\"" : "";
+ }
+ $.each( versions, function( displayName, pathFragment )
+ {
+ switcher_html += '<option value="' + displayName + '" ' + ifselect( displayName ) + '>' + displayName + '</option>';
+ } );
+ switcher_html += '</select></p>';
+ $( "div.logo" ).append( switcher_html );
+ var toURL = function( displayName )
+ {
+ if( window.location.hostname == "qi4j.org" || window.location.hostname == "www.qi4j.org" )
+ {
+ return "../" + versions[ displayName ];
+ }
+ else
+ {
+ return "http://qi4j.org/" + versions[ displayName ];
+ }
+ }
+ $( "div.logo select" ).change( function()
+ {
+ window.location = toURL( $( this ).val() );
+ } );
}
else
- { // Loaded from elsewhere
- window.location = versions[ $( this ).val() ].url;
+ {
+ console.log( "Documentation loaded locally? No version switcher" );
}
} );
@@ -126,13 +109,16 @@ $( document ).ready( function($){
// Section specific enhancements
var $section = $( 'body > div.section' );
- var section_title = $section.attr( 'title' ).trim();
- switch( section_title ) {
- case "Glossary":
- glossary( $section );
- break;
- default:
- break;
+ if( $section.attr( 'title' ) )
+ {
+ var section_title = $section.attr( 'title' ).trim();
+ switch( section_title ) {
+ case "Glossary":
+ glossary( $section );
+ break;
+ default:
+ break;
+ }
}
} );
View
7 versions.json
@@ -0,0 +1,7 @@
+{
+ "develop": "develop",
+ "latest": "latest",
+ "2.0-RC1": "2.0-RC1",
+ "<=1.4.x": "1.4"
+}
+

0 comments on commit 6ac3a11

Please sign in to comment.
Something went wrong with that request. Please try again.