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 f81efc7 SLING-7986 js and syntax cleanup
f81efc7 is described below
commit f81efc7f1d6bf958540ac5722f452dd09a1bbfb0
Author: JE Bailey <[email protected]>
AuthorDate: Tue Oct 9 12:19:53 2018 -0400
SLING-7986 js and syntax cleanup
---
ui/src/main/frontend/src/js/cms.draggable.js | 19 ++++----
ui/src/main/frontend/src/js/cms.suggest.js | 2 +-
ui/src/main/frontend/src/js/cms.toggle.js | 2 +-
ui/src/main/frontend/src/js/nomnom.js | 71 +++++++++++++++-------------
4 files changed, 51 insertions(+), 43 deletions(-)
diff --git a/ui/src/main/frontend/src/js/cms.draggable.js
b/ui/src/main/frontend/src/js/cms.draggable.js
index 39756b7..c3bdc6d 100644
--- a/ui/src/main/frontend/src/js/cms.draggable.js
+++ b/ui/src/main/frontend/src/js/cms.draggable.js
@@ -19,7 +19,7 @@
nomnom.decorate(".is-draggable", class {
- nomnomCallback() {
+ initCallback() {
this.dragData = {
mouseX : 0,
mouseY : 0,
@@ -28,6 +28,15 @@ nomnom.decorate(".is-draggable", class {
elementY : 0
};
}
+
+
+ moveComplete(){
+ this.dragData.mouseDown = false;
+ this.dragData.elementX = parseInt(this.style.left) || 0;
+ this.dragData.elementY = parseInt(this.style.top) || 0;
+ return false;
+ }
+
"mousedown::listen"(event) {
if(event.target.matches('.modal-card-body *')){
@@ -43,14 +52,6 @@ nomnom.decorate(".is-draggable", class {
this.moveComplete();
}
}
-
- moveComplete(){
- this.dragData.mouseDown = false;
- this.dragData.elementX = parseInt(this.style.left) || 0;
- this.dragData.elementY = parseInt(this.style.top) || 0;
- return false;
- }
-
"mousemove::document"(event){
if (this.dragData.mouseDown === false) {
diff --git a/ui/src/main/frontend/src/js/cms.suggest.js
b/ui/src/main/frontend/src/js/cms.suggest.js
index be42c31..dafa80a 100644
--- a/ui/src/main/frontend/src/js/cms.suggest.js
+++ b/ui/src/main/frontend/src/js/cms.suggest.js
@@ -18,7 +18,7 @@
*/
nomnom.decorate("input.pathfield", class {
- nomnomCallback(){
+ initCallback(){
var type = $(this).data('type');
var base = $(this).data('base');
var xhr;
diff --git a/ui/src/main/frontend/src/js/cms.toggle.js
b/ui/src/main/frontend/src/js/cms.toggle.js
index 524261d..1052439 100644
--- a/ui/src/main/frontend/src/js/cms.toggle.js
+++ b/ui/src/main/frontend/src/js/cms.toggle.js
@@ -24,7 +24,7 @@ nomnom.decorate('.toggle-hidden' , class {
});
nomnom.decorate('.toggle-value', class {
- nomnomCallback(){
+ initCallback(){
var source = this.getAttribute('data-toggle-source');
var selector = 'input[name="'+ source +'"], select[name="'+ selector
+'"]';
var $tog = $(this);
diff --git a/ui/src/main/frontend/src/js/nomnom.js
b/ui/src/main/frontend/src/js/nomnom.js
index 891df46..7439cf1 100644
--- a/ui/src/main/frontend/src/js/nomnom.js
+++ b/ui/src/main/frontend/src/js/nomnom.js
@@ -24,10 +24,9 @@
console.log("storing selector" + selector);
}
tagSelectors[selector] = config;
- var nodes = document.querySelectorAll(selector);
- for (var index = 0; index < nodes.length; ++index) {
- wrap(nodes[index], config);
- }
+ document.querySelectorAll(selector).forEach(function(node){
+ wrap(node, config);
+ });
};
var tagSelectors = {};
@@ -65,16 +64,22 @@
var configInstance = new config();
var names = Object.getOwnPropertyNames(config.prototype);
var keys = Object.keys(configInstance);
+ var callback = false;
names.forEach(function(name) {
- if (name !== "constructor") {
- if (debug) {
- console.log(" decorating " + name);
- }
- if (name.indexOf("::") !== -1) {
- registerEventHandler(node, name, configInstance[name]);
- } else {
- node[name] = configInstance[name];
- }
+ if (name === "constructor") {
+ return;
+ }
+ if (name === "initCallback") {
+ callback = configInstance[name];
+ return;
+ }
+ if (debug) {
+ console.log(" decorating " + name);
+ }
+ if (name.indexOf("::") !== -1) {
+ registerEventHandler(node, name, configInstance[name]);
+ } else {
+ node[name] = configInstance[name];
}
});
keys.forEach(function(key) {
@@ -83,8 +88,8 @@
}
node[key] = configInstance[key];
});
- if (node['nomnomCallback']) {
- node['nomnomCallback'].call(node);
+ if (callback){}
+ callback.call(node);
}
};
@@ -136,25 +141,27 @@
}
var check = function(node) {
- if (node.querySelectorAll) {
- for ( var selector in tagSelectors) {
+ if (!node.querySelectorAll) {
+ return;
+ }
+ for ( var selector in tagSelectors) {
+ if (debug) {
+ console.log("checking new nodes for " + selector);
+ }
+ if (node.matches(selector)) {
+ wrap(node, tagSelectors[selector]);
+ return;
+ }
+ var found = node.querySelectorAll(":scope " + selector);
+ if (!found) {
+ return;
+ }
+ found.forEach(function(item) {
if (debug) {
- console.log("checking new nodes for " + selector);
- }
- if (node.matches(selector)) {
- wrap(node, tagSelectors[selector]);
- } else {
- var found = node.querySelectorAll(":scope " + selector);
- if (found) {
- found.forEach(function(item) {
- if (debug) {
- console.log("node found for " + selector);
- }
- wrap(item, tagSelectors[selector])
- });
- }
+ console.log("node found for " + selector);
}
- }
+ wrap(item, tagSelectors[selector])
+ });
}
};