myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject [myfaces-tobago] branch master updated: TOBAGO-1824: tc:page should be loadable via AJAX
Date Thu, 16 Nov 2017 17:15:47 GMT
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new db0f9ec  TOBAGO-1824: tc:page should be loadable via AJAX
db0f9ec is described below

commit db0f9ec229a9161d30ee7bde5adbbd1d2a835e69
Author: Udo Schnurpfeil <lofwyr@apache.org>
AuthorDate: Thu Nov 16 18:14:43 2017 +0100

    TOBAGO-1824: tc:page should be loadable via AJAX
---
 .../tobago-bootstrap/_version/js/tobago-jsf.js     | 18 +++++---
 .../tobago-bootstrap/_version/js/tobago.js         | 49 +++++++++++++++++++---
 2 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-jsf.js
b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-jsf.js
index 91c3b4e..7f0cbb7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-jsf.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-jsf.js
@@ -7630,9 +7630,12 @@ _MF_SINGLTN(_PFX_XHR + "_AjaxResponse", _MF_OBJECT, /** @lends myfaces._impl.xhr
 
                     cDataBlock = cDataBlock.substring(cDataBlock.indexOf("<html"));
 // begin TOBAGO-JSF-JS
-                    var newDoc = document.open("text/html", "replace");
-                    newDoc.write(cDataBlock);
-                    newDoc.close();
+//                     var newDoc = document.open("text/html", "replace");
+//                     newDoc.write(cDataBlock);
+//                     newDoc.close();
+                //change only the body, because change the head doesn't work with CSP
+                    var newPage = jQuery(cDataBlock).filter(".tobago-page");
+                    jQuery(".tobago-page").replaceWith(newPage);
                     resultNode = document.documentElement;
 
 /* original
@@ -7663,9 +7666,12 @@ _MF_SINGLTN(_PFX_XHR + "_AjaxResponse", _MF_OBJECT, /** @lends myfaces._impl.xhr
 // begin TOBAGO-JSF-JS
 // XXX hack
                 if (node.getAttribute('id') === document.getElementsByClassName("tobago-page")[0].getAttribute('id'))
{
-                    newDoc = document.open("text/html", "replace");
-                    newDoc.write(cDataBlock);
-                    newDoc.close();
+                    // newDoc = document.open("text/html", "replace");
+                    // newDoc.write(cDataBlock);
+                    // newDoc.close();
+                  //change only the body, because change the head doesn't work with CSP
+                    newPage = jQuery(cDataBlock).filter(".tobago-page");
+                    jQuery(".tobago-page").replaceWith(newPage);
                     resultNode = document.documentElement;
                 } else {
                     resultNode = this.replaceHtmlItem(request, context, node.getAttribute('id'),
cDataBlock);
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago.js
b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago.js
index 94e2fae..5301f51 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago.js
@@ -1361,6 +1361,35 @@ Tobago.registerListener(Tobago.Codi.init, Tobago.Phase.DOCUMENT_READY);
 
 // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+Tobago.jsf = {
+  VIEW_STATE: "javax.faces.ViewState",
+  CLIENT_WINDOW: "javax.faces.ClientWindow",
+  VIEW_ROOT: "javax.faces.ViewRoot",
+  VIEW_HEAD: "javax.faces.ViewHead",
+  VIEW_BODY: "javax.faces.ViewBody",
+  isId: function (id) {
+    switch (id) {
+      case Tobago.jsf.VIEW_STATE:
+      case Tobago.jsf.CLIENT_WINDOW:
+      case Tobago.jsf.VIEW_ROOT:
+      case Tobago.jsf.VIEW_HEAD:
+      case Tobago.jsf.VIEW_BODY:
+        return false;
+      default:
+        return true;
+    }
+  },
+  isBody: function (id) {
+    switch (id) {
+      case Tobago.jsf.VIEW_ROOT:
+      case Tobago.jsf.VIEW_BODY:
+        return true;
+      default:
+        return false;
+    }
+  }
+};
+
 jsf.ajax.addOnEvent(function (event) {
   console.timeEnd("x"); // @DEV_ONLY
   console.time("x"); // @DEV_ONLY
@@ -1371,12 +1400,20 @@ jsf.ajax.addOnEvent(function (event) {
     jQuery(event.responseXML).find("update").each(function () {
       var id = jQuery(this).attr("id");
       console.info("Update after jsf.ajax success: id='" + id + "'"); // @DEV_ONLY
-      var newElement = jQuery(Tobago.Utils.escapeClientId(id));
-
-      for (var order = 0; order < Tobago.listeners.afterUpdate.length; order++) {
-        var list = Tobago.listeners.afterUpdate[order];
-        for (var i = 0; i < list.length; i++) {
-          list[i](newElement);
+      var newElement;
+      if (Tobago.jsf.isId(id)) {
+        console.log("updating id: " + id);// @DEV_ONLY
+        newElement = jQuery(Tobago.Utils.escapeClientId(id));
+      } else if (Tobago.jsf.isBody(id)) {
+        console.log("updating body");// @DEV_ONLY
+        newElement = jQuery(".tobago-page");
+      }
+      if (newElement) {
+        for (var order = 0; order < Tobago.listeners.afterUpdate.length; order++) {
+          var list = Tobago.listeners.afterUpdate[order];
+          for (var i = 0; i < list.length; i++) {
+            list[i](newElement);
+          }
         }
       }
     });

-- 
To stop receiving notification emails like this one, please contact
['"commits@myfaces.apache.org" <commits@myfaces.apache.org>'].

Mime
View raw message