polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [38/50] [abbrv] zest-qi4j git commit: WebSite: build the version switcher from ../versions.json
Date Fri, 17 Apr 2015 16:05:58 GMT
WebSite: build the version switcher from ../versions.json

This means that we don't have to update "old" documentation to add new
versions to the switcher, only enhance the versions.json file.


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/055d96c5
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/055d96c5
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/055d96c5

Branch: refs/heads/master
Commit: 055d96c505eb96e8ce2e7e9fbe6dba73046a9483
Parents: fbdec84
Author: Paul Merlin <paul@nosphere.org>
Authored: Sun Mar 24 12:45:05 2013 +0100
Committer: Paul Merlin <paul@nosphere.org>
Committed: Sun Mar 24 12:45:05 2013 +0100

----------------------------------------------------------------------
 manual/src/docs/website/xsl/head.xsl            |   4 -
 .../src/resources/js/progressive-enhancement.js |  97 ++++----
 manual/src/resources/js/versionswitcher.js      | 222 -------------------
 3 files changed, 45 insertions(+), 278 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/055d96c5/manual/src/docs/website/xsl/head.xsl
----------------------------------------------------------------------
diff --git a/manual/src/docs/website/xsl/head.xsl b/manual/src/docs/website/xsl/head.xsl
index 7ddc17c..4d2c06c 100644
--- a/manual/src/docs/website/xsl/head.xsl
+++ b/manual/src/docs/website/xsl/head.xsl
@@ -49,10 +49,6 @@
 
 <script type="text/javascript" src="js/tablestyler.js"></script>
 
-<!-- Version Switcher -->
-
-<script type="text/javascript" src="js/versionswitcher.js"></script>
-
 <!-- Qi4j WebSite Progressive Enhancement -->
 
 <link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" />

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/055d96c5/manual/src/resources/js/progressive-enhancement.js
----------------------------------------------------------------------
diff --git a/manual/src/resources/js/progressive-enhancement.js b/manual/src/resources/js/progressive-enhancement.js
index fb528ee..897e543 100644
--- a/manual/src/resources/js/progressive-enhancement.js
+++ b/manual/src/resources/js/progressive-enhancement.js
@@ -48,55 +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'
-        },
-        '<=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" );
         }
     } );
 
@@ -119,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;
+        }
     }
 
 } );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/055d96c5/manual/src/resources/js/versionswitcher.js
----------------------------------------------------------------------
diff --git a/manual/src/resources/js/versionswitcher.js b/manual/src/resources/js/versionswitcher.js
deleted file mode 100644
index 1b2a34d..0000000
--- a/manual/src/resources/js/versionswitcher.js
+++ /dev/null
@@ -1,222 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-jQuery( window ).load( function()
-{
-  jQuery.getScript("../versions.js", function()
-  {
-    // availableDocVersions is now set
-    versionSwitcher( jQuery );
-  } );
-} );
-
-/**
- * Utility to browse different versions of the documentation.
- * Requires the ../versions.js file in place in place, which
- * lists the available (relevant) versions of the manual.
- * The version to load at page load can be given via the
- * search string, for example ?1.3
- */
-function versionSwitcher( $ )
-{
-  var VERSION_AND_PAGE = /chunked\/(.*)\/(.*\.html)?/;
-  var contentElements = [ "", "section", "chapter", "book", "part" ];
-  var CONTENT_ELEMENT = contentElements.join( ",body>div." ).replace( /^,/, " " );
-  var CONTENT_ELEMENT_LOAD = contentElements.join( ",div." ).replace( /^,/, " " );
-  var url = window.location;
-  var path = url.pathname;
-  var pathinfo = getVersionAndPage( path );
-  if ( !pathinfo ) return;
-  var currentVersion = pathinfo.version;
-  var LOAD_FROM_VERSION = currentVersion;
-  var currentPage = pathinfo.page;
-
-  var contentElement = $( CONTENT_ELEMENT );
-
-  var versionSelector = $( '<select id="version-selector" name="version-selector"></select>'
);
-
-  loadVersionsIntoSelector( availableDocVersions, versionSelector );
-
-  // select the current option
-  setSelector2CurrentVersion( versionSelector, currentVersion );
-
-  // add the dropdown to the page
-  $("div.navheader").append( versionSelector );
-
-  // handle changes in the dropdown
-  versionSelector.change( function()
-  {
-    if ( this.selectedIndex === -1 ) return;
-    var newVersion = this.options[this.selectedIndex].value;
-    loadNewVersion( newVersion );
-  } );
-
-  // PRIVATE FUNCTIONS
-
-  /**
-   * Load an array of version into a select element and
-   * check if the current page actually exists in these versions.
-   * Non-existing entries will be disabled.
-   */
-  function loadVersionsIntoSelector( availableDocVersions, versionSelector )
-  {
-    $.each( availableDocVersions, function( index, version )
-    {
-      // add options in disabled state, then enable if the head request was successful
-      var newOption = $( '<option disabled="disabled" value="' + version + '">' + version
+ '</option>' );
-      versionSelector.append( newOption );
-      checkExistence( version, currentPage, function () 
-      {
-        newOption.removeAttr( 'disabled' );
-      } );
-    } );
-  }
-
-  /**
-   * Set the given version as the selected element in the version selector.
-   * If the version is missing, it will be added.
-   */
-  function setSelector2CurrentVersion( versionSelector, version )
-  {
-    var currentOptionElement = versionSelector.children( '[value="' + version + '"]' );
-    if ( currentOptionElement.length === 0 )
-    {
-      // add a new option, as the current version wasn't in the list
-      var newOption = new Option( version, version );
-      newOption.selected = true;
-      versionSelector.prepend( newOption );
-    }
-    else
-    {
-      currentOptionElement.attr( "selected", true );
-    }
-  }
-
-  /**
-   * Load page contents from a different version into the page.
-   * Also loads navigation header/footer from that version.
-   */
-  function loadNewVersion ( newVersion )
-  {
-    redirect2NewVersion( newVersion );
-  }
-
-  /**
-   * Redirect to another version.
-   */
-  function redirect2NewVersion ( newVersion )
-  {
-    location.assign( "/chunked/" + newVersion + "/" + currentPage );
-  }
-
-  /**
-   * Load page contents from a different version into the page.
-   * Also loads navigation header/footer from that version.
-   */
-  function loadNewVersionIntoPage ( newVersion )
-  {
-    contentElement.load( "/chunked/" + newVersion + "/" + currentPage + CONTENT_ELEMENT_LOAD,
function( response, status )
-
-    {
-      if ( status == "success" )
-      {
-        SyntaxHighlighter.highlight();
-        // append version to URL to enable browsing of a different version
-        fixNavigation ( $( "a.xref, div.toc a", contentElement ), newVersion );
-        // load the navheader and navfooter as well
-        loadPart( "navheader", newVersion, currentPage );
-        loadPart( "navfooter", newVersion, currentPage );
-      }
-    } );
-  }
-
-  /**
-   * Change links to enable smooth browsing of a different version.
-   * Links that are present in the "base version" as well will get the
-   * version to browse added to their URL, while those which
-   * are not present will be directly linked to the old version instead.
-   */
-  function fixNavigation( elements, version )
-  {
-    if ( LOAD_FROM_VERSION === version ) return;
-    elements.each( function()
-    {
-      var link = this;
-      var versionAndPage = getVersionAndPage( link.href );
-      if ( versionAndPage )
-      {
-        checkUrlExistence( link, function ()
-        {
-          link.href = versionAndPage.page + "?" + version;
-          }, function()
-        {
-          link.href = "../" + version + "/" + versionAndPage.page;
-        } );
-      }
-    } );
-  }
-  
-  /**
-   * Load a specific part of the page (not the main content).
-   */
-  function loadPart( partName, newVersion, currentPage )
-  {
-    $( "div." + partName ).load( "/chunked/" + newVersion + "/" + currentPage + " div." +
partName, function ( response, status ) 
-    {
-      if ( status == "success")
-      {
-        fixNavigation( $( "div." + partName + " a" ), newVersion );
-      }
-    } );
-  }
-
-  /**
-   * Check if a specific version of a page exists.
-   * The success and failure functions will be automatically called on finish.
-   */
-  function checkExistence( version, page, success, failure )
-  {
-     var url = "../" + version + "/" + page;
-     checkUrlExistence ( url, success, failure );
-  }
-  
-  /**
-   * Check if a specific URL exists.
-   * The success and failure functions will be automatically called on finish.
-   */
-  function checkUrlExistence( url, success, failure )
-  {
-    var settings = { "type": "HEAD", "async": true, "url": url };
-    if ( success ) settings.success = success;
-    if ( failure ) settings.error = failure;
-    $.ajax( settings );
-  }
-
-  /**
-   * Parse a path to extract version number and page filename.
-   */
-  function getVersionAndPage( path )
-  {
-    var pathinfo = path.match( VERSION_AND_PAGE );
-    if ( !pathinfo || !pathinfo[1] ) return null;
-    var currentVersion = pathinfo[1];
-    var currentPage = pathinfo[2] ? pathinfo[2] : "index.html";
-    return { version: currentVersion, page: currentPage };
-  }
-}
-


Mime
View raw message