This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git


The following commit(s) were added to refs/heads/master by this push:
     new 9afcff0  SLING-7986 updated lib and separated toggle and suggest
9afcff0 is described below

commit 9afcff047399218c636158c6d9e9ede7af401249
Author: JE Bailey <[email protected]>
AuthorDate: Mon Oct 8 14:45:12 2018 -0400

    SLING-7986 updated lib and separated toggle and suggest
---
 ui/src/main/frontend/gulpfile.js                   |  2 +
 ui/src/main/frontend/src/js/cms.js                 | 66 +---------------------
 ui/src/main/frontend/src/js/cms.modal.js           | 27 ++++++---
 .../src/js/{cms.modal.js => cms.suggest.js}        | 30 +++++++---
 .../src/js/{cms.modal.js => cms.toggle.js}         | 28 ++++++---
 ui/src/main/frontend/src/js/nomnom.js              | 13 ++++-
 6 files changed, 78 insertions(+), 88 deletions(-)

diff --git a/ui/src/main/frontend/gulpfile.js b/ui/src/main/frontend/gulpfile.js
index aae3faf..caa81eb 100755
--- a/ui/src/main/frontend/gulpfile.js
+++ b/ui/src/main/frontend/gulpfile.js
@@ -92,6 +92,8 @@ gulp.task('cms-js', function() {
             './src/js/cms.form.js',
             './src/js/cms.modal.js',
             './src/js/cms.upload.js',
+            './src/js/cms.toggle.js',
+            './src/js/cms.suggest.js',
             './src/js/cms.draggable.js',
             './src/js/cms.js'
         ])
diff --git a/ui/src/main/frontend/src/js/cms.js 
b/ui/src/main/frontend/src/js/cms.js
index c81e38e..8682e4a 100644
--- a/ui/src/main/frontend/src/js/cms.js
+++ b/ui/src/main/frontend/src/js/cms.js
@@ -48,21 +48,8 @@ Sling.CMS = {
                     complete();
                 });
                 return $modal;
-            },
-            fetchModal: function(title, link, path, complete){
-                var $modal = $('<div class="modal"><div 
class="modal-background"></div><div class="modal-card is-draggable"><header 
class="modal-card-head"><p class="modal-card-title">'+title+'</p><button 
class="delete" aria-label="close"></button></header><section 
class="modal-card-body"></section><footer 
class="modal-card-foot"></footer></div>');
-                $('body').append($modal);
-                $modal.find('.modal-card-body').load(link + " " 
+path,function(){
-                    $modal.addClass('is-active');
-                    $modal.find('.delete,.close-modal').click(function(){
-                        $modal.css('display','none').remove();
-                        return false;
-                    });
-                    Sling.CMS.decorate($modal);
-                    complete();
-                });
-                return $modal;
             }
+
         },
         utils: {
             form2Obj: function ($form){
@@ -160,34 +147,6 @@ Sling.CMS = {
         }
     };
 
-    Sling.CMS.ext['pathfield'] = {
-        suggest: function(field, type, base) {
-            var xhr;
-            new autoComplete({
-                minChars: 1,
-                selector: field,
-                source: function(term, response){
-                    try {
-                        xhr.abort();
-                    } catch(e){}
-                    if(term === '/'){
-                        term = base;
-                    }
-                    xhr = $.getJSON('/bin/cms/paths', { path: term, type: type 
}, function(data){
-                        response(data);
-                    });
-                }
-            });
-        },
-        decorate: function($ctx){
-            $ctx.find('input.pathfield').each(function(){
-                var type = $(this).data('type');
-                var base = $(this).data('base');
-                Sling.CMS.ext.pathfield.suggest(this, type, base);
-            });
-        }
-    };
-
     Sling.CMS.ext['reload'] = function(res, msg) {
         if(window.self !== window.top){
             window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){
@@ -349,28 +308,7 @@ Sling.CMS = {
         }
     };
     
-    Sling.CMS.ext['toggle-hidden'] = {
-        decorate: function($ctx){
-            $ctx.find('.toggle-hidden').click(function(){
-                $($(this).data('target')).toggleClass('is-hidden');
-            });
-        }
-    };
-    
-    Sling.CMS.ext['toggle-value'] = {
-        decorate: function($ctx) {
-            $ctx.find('.toggle-value').each(function(){
-                var $tog = $(this);
-                $('input[name="'+$tog.data('toggle-source')+'"], 
select[name="'+$tog.data('toggle-source')+'"]').change(function(){
-                    if($(this).val() !== $tog.data('toggle-value')){
-                        $tog.addClass('is-hidden');
-                    } else {
-                        $tog.removeClass('is-hidden');
-                    }
-                });
-            })
-        }
-    };
+
 
     $(document).ready(function() {
         Sling.CMS.init();
diff --git a/ui/src/main/frontend/src/js/cms.modal.js 
b/ui/src/main/frontend/src/js/cms.modal.js
index bd7cb77..505d4ee 100644
--- a/ui/src/main/frontend/src/js/cms.modal.js
+++ b/ui/src/main/frontend/src/js/cms.modal.js
@@ -17,11 +17,24 @@
  * under the License.
  */
 nomnom.decorate("a.Fetch-Modal", class {
-  "click::handler"() {
-    var link = this;
-    link.setAttribute("disabled",'disabled');
-    Sling.CMS.ui.fetchModal(link.getAttribute('data-title'), 
encodeURI(link.getAttribute('href')), link.getAttribute('data-path'), 
function(event){
-      link.removeAttribute('disabled');
-    });
-  }
+    
+    "click::handler"() {
+        this.setAttribute("disabled",'disabled');
+        this.getModal(this.getAttribute('data-title'), 
encodeURI(this.getAttribute('href')), this.getAttribute('data-path'));
+    }
+  
+    getModal(title, link, path, complete) {
+        var button = this;
+        var $modal = $('<div class="modal"><div 
class="modal-background"></div><div class="modal-card is-draggable"><header 
class="modal-card-head"><p class="modal-card-title">'+title+'</p><button 
class="delete" aria-label="close"></button></header><section 
class="modal-card-body"></section><footer 
class="modal-card-foot"></footer></div>');
+        $('body').append($modal);
+            $modal.find('.modal-card-body').load(link + " " +path,function(){
+            $modal.addClass('is-active');
+            $modal.find('.delete,.close-modal').click(function(){
+                $modal.css('display','none').remove();
+                return false;
+            });
+            button.removeAttribute("disabled");
+        });
+        return $modal;
+    }
 });
diff --git a/ui/src/main/frontend/src/js/cms.modal.js 
b/ui/src/main/frontend/src/js/cms.suggest.js
similarity index 54%
copy from ui/src/main/frontend/src/js/cms.modal.js
copy to ui/src/main/frontend/src/js/cms.suggest.js
index bd7cb77..5b57d53 100644
--- a/ui/src/main/frontend/src/js/cms.modal.js
+++ b/ui/src/main/frontend/src/js/cms.suggest.js
@@ -16,12 +16,26 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-nomnom.decorate("a.Fetch-Modal", class {
-  "click::handler"() {
-    var link = this;
-    link.setAttribute("disabled",'disabled');
-    Sling.CMS.ui.fetchModal(link.getAttribute('data-title'), 
encodeURI(link.getAttribute('href')), link.getAttribute('data-path'), 
function(event){
-      link.removeAttribute('disabled');
-    });
-  }
+
+nomnom.decorate("input.pathfield", class {
+    init(){
+        var type = $(this).data('type');
+        var base = $(this).data('base');
+        var xhr;
+        new autoComplete({
+            minChars: 1,
+            selector: this,
+            source: function(term, response){
+                try {
+                    xhr.abort();
+                } catch(e){}
+                if(term === '/'){
+                    term = base;
+                }
+                xhr = $.getJSON('/bin/cms/paths', { path: term, type: type }, 
function(data){
+                    response(data);
+                });
+            }
+        });
+    } 
 });
diff --git a/ui/src/main/frontend/src/js/cms.modal.js 
b/ui/src/main/frontend/src/js/cms.toggle.js
similarity index 55%
copy from ui/src/main/frontend/src/js/cms.modal.js
copy to ui/src/main/frontend/src/js/cms.toggle.js
index bd7cb77..4dda713 100644
--- a/ui/src/main/frontend/src/js/cms.modal.js
+++ b/ui/src/main/frontend/src/js/cms.toggle.js
@@ -16,12 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-nomnom.decorate("a.Fetch-Modal", class {
-  "click::handler"() {
-    var link = this;
-    link.setAttribute("disabled",'disabled');
-    Sling.CMS.ui.fetchModal(link.getAttribute('data-title'), 
encodeURI(link.getAttribute('href')), link.getAttribute('data-path'), 
function(event){
-      link.removeAttribute('disabled');
-    });
-  }
+
+nomnom.decorate('.toggle-hidden' , class {
+    "click::this"(){
+        $($(this).data('target')).toggleClass('is-hidden');
+    }
+});
+    
+nomnom.decorate('.toggle-value', class {
+    init(){
+        var source = this.getAttribute('data-toggle-source');
+        var selector = 'input[name="'+ source +'"], select[name="'+ selector 
+'"]';
+        var $tog = $(this);
+        $(selector).change(function(){
+            if($(this).val() !== $tog.data('toggle-value')){
+                $tog.addClass('is-hidden');
+            } else {
+                $tog.removeClass('is-hidden');
+            }
+        });
+    }
 });
diff --git a/ui/src/main/frontend/src/js/nomnom.js 
b/ui/src/main/frontend/src/js/nomnom.js
index fc4f522..8144c0c 100644
--- a/ui/src/main/frontend/src/js/nomnom.js
+++ b/ui/src/main/frontend/src/js/nomnom.js
@@ -31,8 +31,8 @@
     };
 
     var tagSelectors = {};
-
     var debug = false;
+    var elementMap = new WeakMap();
 
     new MutationObserver(function(mutations) {
         mutations.forEach(function(mutation) {
@@ -51,6 +51,17 @@
         if (debug) {
             console.log("decorating element " + node + node.name);
         }
+        var configSet;
+        if (elementMap.has(node)){
+            configSet = elementMap.get(node);
+        } else {
+            configSet = new Set();
+            elementMap.set(node,configSet);
+        }
+        if (configSet.has(config)){
+            return;
+        }
+        configSet.add(config);
         var names = Object.getOwnPropertyNames(config.prototype);
         names.forEach(function(name) {
             if (debug) {

Reply via email to