[Libreoffice-commits] help.git: 3 commits - source/help.js

Jan Holesovsky kendy at collabora.com
Thu Dec 22 20:26:56 UTC 2016


 source/help.js |   61 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 18 deletions(-)

New commits:
commit bfe8593e120f83c936dc91fd40ece2e98c04603c
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Dec 22 21:25:00 2016 +0100

    help.js: Chrome returns 0 when using the local files.
    
    Note: help.js works in Chrome only when you run it with
    --allow-file-access-from-files.

diff --git a/source/help.js b/source/help.js
index b97721e..eac85ba 100644
--- a/source/help.js
+++ b/source/help.js
@@ -81,7 +81,7 @@ function displayXML(xml, xsl, urlVars, moduleName, language, system) {
 
                 loadXMLDoc(fileName, function() {
                     var xmlDoc = this.responseXML;
-                    if (this.status == 200 && xmlDoc != null) {
+                    if (xmlDoc != null) {
                         var resultDocument = xsltProcessor.transformToFragment(xmlDoc,  document);
                         $("#DisplayArea").html($(resultDocument).find('#DisplayArea').html());
                         $("#TopRight").html('<p class="bug">Contents displayed is: ' + fileName + '</p>');
@@ -108,10 +108,10 @@ function displayResult(file, moduleName, language, system) {
         var xsl = this.responseXML;
 
         // load the actual XHP file
-        if (this.status == 200 && xsl != null) {
+        if (xsl != null) {
             loadXMLDoc(file, function(){
                 var xml = this.responseXML;
-                if (this.status == 200 && xml != null) {
+                if (xml != null) {
                     displayXML(xml, xsl, getUrlVars(file), moduleName, language, system);
                 }
                 else {
commit 805e50ccdd54fc1604316e8335d1b4c21ed39a9a
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Dec 22 19:03:52 2016 +0100

    help.js: Use the async XMLHttpRequest.

diff --git a/source/help.js b/source/help.js
index 5d7d5f7..b97721e 100644
--- a/source/help.js
+++ b/source/help.js
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-function loadXMLDoc(filename)
+function loadXMLDoc(filename, handler)
 {
     if (window.ActiveXObject)
     {
@@ -18,13 +18,13 @@ function loadXMLDoc(filename)
         xhttp = new XMLHttpRequest();
     }
 
-    xhttp.open("GET", filename, false);
+    xhttp.open("GET", filename);
+    xhttp.onload = handler;
     try {
         xhttp.responseType = "msxml-document"
     } catch(err) {} // Helping IE11
 
-    xhttp.send("");
-    return xhttp.responseXML;
+    xhttp.send();
 }
 
 function getParameterByName(name, url) {
@@ -47,14 +47,10 @@ function getParameterByName(name, url) {
     return decodeURIComponent(results[2].replace(/\+/g, " "));
 }
 
-function displayResult(file, moduleName, language, system)
-{
-    var xml = loadXMLDoc(file);
-    var xsl = loadXMLDoc('online_transform.xsl');
+function displayXML(xml, xsl, urlVars, moduleName, language, system) {
     var xsltProcessor;
     var resultDocument;
     var bookmarkHTML;
-    var urlVars = getUrlVars(file);
     var module = urlVars["DbPAR"];
     moduleName = moduleName || module;
     var language = urlVars["Language"];
@@ -80,12 +76,22 @@ function displayResult(file, moduleName, language, system)
         $(document).on('click', '#BottomLeft a, #DisplayArea a', function(e) {
                 e.preventDefault();
                 $('#search-bar').val('');
-                var xml = loadXMLDoc($(this).attr('href'));
-                var resultDocument = xsltProcessor.transformToFragment(xml,  document);
-                $("#DisplayArea").html($(resultDocument).find('#DisplayArea').html());
-                $("#TopRight").html('<p class="bug">Contents displayed is: '+$(this).attr('href')+'</p>');
-                return false;
+
+                var fileName = $(this).attr('href');
+
+                loadXMLDoc(fileName, function() {
+                    var xmlDoc = this.responseXML;
+                    if (this.status == 200 && xmlDoc != null) {
+                        var resultDocument = xsltProcessor.transformToFragment(xmlDoc,  document);
+                        $("#DisplayArea").html($(resultDocument).find('#DisplayArea').html());
+                        $("#TopRight").html('<p class="bug">Contents displayed is: ' + fileName + '</p>');
+                    }
+                    else {
+                        console.log('Cannot load ' + fileName);
+                    }
                 });
+                return false;
+            });
 
         xsltProcessor.importStylesheet(xsl);
         resultDocument = xsltProcessor.transformToFragment(xml,  document);
@@ -96,6 +102,29 @@ function displayResult(file, moduleName, language, system)
     }
 }
 
+function displayResult(file, moduleName, language, system) {
+    // load the XSLT
+    loadXMLDoc('online_transform.xsl', function() {
+        var xsl = this.responseXML;
+
+        // load the actual XHP file
+        if (this.status == 200 && xsl != null) {
+            loadXMLDoc(file, function(){
+                var xml = this.responseXML;
+                if (this.status == 200 && xml != null) {
+                    displayXML(xml, xsl, getUrlVars(file), moduleName, language, system);
+                }
+                else {
+                    console.log('Cannot load ' + file);
+                }
+            });
+        }
+        else {
+            console.log('Cannot load online_transform.xsl');
+        }
+    });
+}
+
 var debouncer = null;
 $(document).ready(function() {
         $('#search-bar').keyup(function() {
commit 76df8c42a30d1dd3a6bd015a28d36325d4798174
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Dec 22 18:29:20 2016 +0100

    help.js: Remove a param that is always '1'.

diff --git a/source/help.js b/source/help.js
index 7cc7157..5d7d5f7 100644
--- a/source/help.js
+++ b/source/help.js
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-function loadXMLDoc(filename, response)
+function loadXMLDoc(filename)
 {
     if (window.ActiveXObject)
     {
@@ -24,11 +24,7 @@ function loadXMLDoc(filename, response)
     } catch(err) {} // Helping IE11
 
     xhttp.send("");
-    if (response == 1) {
-        return xhttp.responseXML;
-    }
-
-    return xhttp.responseText;
+    return xhttp.responseXML;
 }
 
 function getParameterByName(name, url) {
@@ -53,8 +49,8 @@ function getParameterByName(name, url) {
 
 function displayResult(file, moduleName, language, system)
 {
-    var xml = loadXMLDoc(file, 1);
-    var xsl = loadXMLDoc('online_transform.xsl', 1);
+    var xml = loadXMLDoc(file);
+    var xsl = loadXMLDoc('online_transform.xsl');
     var xsltProcessor;
     var resultDocument;
     var bookmarkHTML;
@@ -84,7 +80,7 @@ function displayResult(file, moduleName, language, system)
         $(document).on('click', '#BottomLeft a, #DisplayArea a', function(e) {
                 e.preventDefault();
                 $('#search-bar').val('');
-                var xml = loadXMLDoc($(this).attr('href'), 1);
+                var xml = loadXMLDoc($(this).attr('href'));
                 var resultDocument = xsltProcessor.transformToFragment(xml,  document);
                 $("#DisplayArea").html($(resultDocument).find('#DisplayArea').html());
                 $("#TopRight").html('<p class="bug">Contents displayed is: '+$(this).attr('href')+'</p>');


More information about the Libreoffice-commits mailing list