guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mjum...@apache.org
Subject [26/50] incubator-guacamole-client git commit: GUAC-1378: Define HTML patches using a special <guac-patch> root element.
Date Sun, 20 Mar 2016 02:22:06 GMT
GUAC-1378: Define HTML patches using a special <guac-patch> root element.

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/9c113632
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/9c113632
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/9c113632

Branch: refs/heads/master
Commit: 9c11363224b8c362cd3b7051d933d94fcf900de1
Parents: 5e6c9c2
Author: Michael Jumper <mike.jumper@guac-dev.org>
Authored: Thu Feb 18 13:34:07 2016 -0800
Committer: Michael Jumper <mike.jumper@guac-dev.org>
Committed: Thu Feb 18 13:34:07 2016 -0800

----------------------------------------------------------------------
 .../index/config/templateRequestDecorator.js    | 42 +++++++++++++++++++-
 1 file changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/9c113632/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js b/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
index b4c78c7..cb848c3 100644
--- a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
+++ b/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
@@ -32,6 +32,18 @@ angular.module('index').config(['$provide', function($provide) {
         var $q = $injector.get('$q');
 
         /**
+         * Array of the root elements of all patches which should be applied to
+         * the HTML of retrieved templates.
+         *
+         * @type Element[]
+         */
+        var patches = [
+            $('<guac-patch before="a"><p>HELLO BEFORE</p></guac-patch>')[0],
+            $('<guac-patch after="a"><p>HELLO AFTER</p></guac-patch>')[0],
+            $('<guac-patch replace="div.protocol"><div class="protocol">:-)</div></guac-patch>')[0]
+        ];
+
+        /**
          * Invokes $templateRequest() with all arguments exactly as provided,
          * applying all HTML patches from any installed Guacamole extensions
          * to the HTML of the requested template.
@@ -50,8 +62,34 @@ angular.module('index').config(['$provide', function($provide) {
                 // Parse HTML into DOM tree
                 var root = $('<div></div>').html(data);
 
-                // STUB: Apply HTML patches
-                root.find('a').after('<p>HELLO</p>');
+                // Apply all defined patches
+                angular.forEach(patches, function applyPatch(patch) {
+
+                    // Ignore any patches which are malformed
+                    if (patch.tagName !== 'GUAC-PATCH')
+                        return;
+
+                    // Insert after any elements which match the "after"
+                    // selector (if defined)
+                    var after = patch.getAttribute('after');
+                    if (after)
+                        root.find(after).after(patch.innerHTML);
+
+                    // Insert before any elements which match the "before"
+                    // selector (if defined)
+                    var before = patch.getAttribute('before');
+                    if (before)
+                        root.find(before).before(patch.innerHTML);
+
+                    // Replace any elements which match the "replace" selector
+                    // (if defined)
+                    var replace = patch.getAttribute('replace');
+                    if (replace)
+                        root.find(replace).html(patch.innerHTML);
+
+                    // Ignore all other attributes
+
+                });
 
                 // Transform back into HTML
                 deferred.resolve.call(this, root.html());


Mime
View raw message