Built motion from commit (unavailable).|2.5.2
[motion2.git] / apidoc / main.js
index 8adc385..e2128f6 100644 (file)
@@ -8,11 +8,13 @@ require.config({
         locales: './locales/locale',
         lodash: './vendor/lodash.custom.min',
         pathToRegexp: './vendor/path-to-regexp/index',
-        prettify: './vendor/prettify/prettify',
+        prismjs: './vendor/prism',
         semver: './vendor/semver.min',
         utilsSampleRequest: './utils/send_sample_request',
         webfontloader: './vendor/webfontloader',
-        list: './vendor/list.min'
+        list: './vendor/list.min',
+        apiData: './api_data',
+        apiProject: './api_project',
     },
     shim: {
         bootstrap: {
@@ -28,12 +30,12 @@ require.config({
             deps: ['jquery', 'handlebars'],
             exports: 'Handlebars'
         },
-        prettify: {
-            exports: 'prettyPrint'
-        }
+        prismjs: {
+            exports: 'Prism'
+        },
     },
     urlArgs: 'v=' + (new Date()).getTime(),
-    waitSeconds: 15
+    waitSeconds: 150
 });
 
 require([
@@ -41,20 +43,34 @@ require([
     'lodash',
     'locales',
     'handlebarsExtended',
-    './api_project.js',
-    './api_data.js',
-    'prettify',
+    'apiProject',
+    'apiData',
+    'prismjs',
     'utilsSampleRequest',
     'semver',
     'webfontloader',
     'bootstrap',
     'pathToRegexp',
     'list'
-], function($, _, locale, Handlebars, apiProject, apiData, prettyPrint, sampleRequest, semver, WebFont) {
+], function($, _, locale, Handlebars, apiProject, apiData, Prism, sampleRequest, semver, WebFont) {
 
-    // load google web fonts
-    loadGoogleFontCss();
+    // Load google web fonts.
+    WebFont.load({
+        active: function() {
+            // Only init after fonts are loaded.
+            init($, _, locale, Handlebars, apiProject, apiData, Prism, sampleRequest, semver);
+        },
+        inactive: function() {
+            // Run init, even if loading fonts fails
+            init($, _, locale, Handlebars, apiProject, apiData, Prism, sampleRequest, semver);
+        },
+        google: {
+            families: ['Source Code Pro', 'Source Sans Pro:n4,n6,n7']
+        }
+    });
+});
 
+function init($, _, locale, Handlebars, apiProject, apiData, Prism, sampleRequest, semver) {
     var api = apiData.api;
 
     //
@@ -385,7 +401,7 @@ require([
     $('#sections').append( content );
 
     // Bootstrap Scrollspy
-    $(this).scrollspy({ target: '#scrollingNav', offset: 18 });
+    $(this).scrollspy({ target: '#scrollingNav' });
 
     // Content-Scroll on Navigation click.
     $('.sidenav').find('a').on('click', function(e) {
@@ -396,13 +412,6 @@ require([
         window.location.hash = $(this).attr('href');
     });
 
-    // Quickjump on Pageload to hash position.
-    if(window.location.hash) {
-        var id = window.location.hash;
-        if ($(id).length > 0)
-            $('html,body').animate({ scrollTop: parseInt($(id).offset().top) }, 0);
-    }
-
     /**
      * Check if Parameter (sub) List has a type Field.
      * Example: @apiSuccess          varname1 No type.
@@ -518,6 +527,7 @@ require([
 
         // init modules
         sampleRequest.initDynamic();
+        Prism.highlightAll()
     }
     initDynamic();
 
@@ -528,18 +538,17 @@ require([
         }
     }
 
-    // Pre- / Code-Format
-    prettyPrint();
-
     //
     // HTML-Template specific jQuery-Functions
     //
     // Change Main Version
-    $('#versions li.version a').on('click', function(e) {
-        e.preventDefault();
-
-        var selectedVersion = $(this).html();
-        $('#version strong').html(selectedVersion);
+    function setMainVersion(selectedVersion) {
+        if (typeof(selectedVersion) === 'undefined') {
+            selectedVersion = $('#version strong').html();
+        }
+        else {
+            $('#version strong').html(selectedVersion);
+        }
 
         // hide all
         $('article').addClass('hide');
@@ -575,6 +584,13 @@ require([
 
         initDynamic();
         return;
+    }
+    setMainVersion();
+
+    $('#versions li.version a').on('click', function(e) {
+        e.preventDefault();
+
+        setMainVersion($(this).html());
     });
 
     // compare all article with their predecessor
@@ -592,11 +608,17 @@ require([
     if ($.urlParam('compare')) {
         // URL Paramter ?compare=1 is set
         $('#compareAllWithPredecessor').trigger('click');
+    }
 
-        if (window.location.hash) {
-            var id = window.location.hash;
-            $('html,body').animate({ scrollTop: parseInt($(id).offset().top) - 18 }, 0);
-        }
+    // Quick jump on page load to hash position.
+    // Should happen after setting the main version
+    // and after triggering the click on the compare button,
+    // as these actions modify the content
+    // and would make it jump to the wrong position or not jump at all.
+    if (window.location.hash) {
+        var id = window.location.hash;
+        if ($(id).length > 0)
+            $('html,body').animate({ scrollTop: parseInt($(id).offset().top) }, 0);
     }
 
     /**
@@ -855,21 +877,6 @@ require([
     }
 
     /**
-     * Load google fonts.
-     */
-    function loadGoogleFontCss() {
-        WebFont.load({
-            active: function() {
-                // Update scrollspy
-                $(window).scrollspy('refresh')
-            },
-            google: {
-                families: ['Source Code Pro', 'Source Sans Pro:n4,n6,n7']
-            }
-        });
-    }
-
-    /**
      * Return ordered entries by custom order and append not defined entries to the end.
      * @param  {String[]} elements
      * @param  {String[]} order
@@ -899,5 +906,5 @@ require([
         });
         return results;
     }
-
-});
+    Prism.highlightAll()
+}