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

dklco 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 8847718  Some further refactoring of the JS code
8847718 is described below

commit 8847718f0b0dd0eb3f43e3f57527c3b3b1944364
Author: Dan Klco <[email protected]>
AuthorDate: Sat Oct 20 13:33:01 2018 -0400

    Some further refactoring of the JS code
---
 ui/src/main/frontend/src/js/cms.fields.js    | 49 +++++++++++++-
 ui/src/main/frontend/src/js/cms.modal.js     |  4 +-
 ui/src/main/frontend/src/js/cms.pathfield.js | 12 ++--
 ui/src/main/frontend/src/js/cms.toggle.js    | 95 +++++++++++++++-------------
 ui/src/main/frontend/src/js/cms.upload.js    | 31 ---------
 5 files changed, 106 insertions(+), 85 deletions(-)

diff --git a/ui/src/main/frontend/src/js/cms.fields.js 
b/ui/src/main/frontend/src/js/cms.fields.js
index cb663b9..feed710 100644
--- a/ui/src/main/frontend/src/js/cms.fields.js
+++ b/ui/src/main/frontend/src/js/cms.fields.js
@@ -23,16 +23,30 @@
 /* eslint-env browser, es6 */
 (function (nomnom) {
     'use strict';
+    
+    /* Update the name on file selection */
+    nomnom.decorate(".file", {
+        events: {
+            input: {
+                change : function (event) {
+                    var nameField = this.querySelector('.file-name');
+                    if (nameField) {
+                        nameField.textContent = event.target.files[0].name;
+                    }
+                }
+            }
+        }
+    });
 
     /* Support for updating the namehint when creating a component */
     nomnom.decorate(".namehint", {
-        initCallback: function(){
+        initCallback: function () {
             var field = this;
-            
this.closest('.Form-Ajax').querySelector('select[name="sling:resourceType"]').addEventListener('change',function(evt){
+            
this.closest('.Form-Ajax').querySelector('select[name="sling:resourceType"]').addEventListener('change',
 function (evt) {
                 var resourceType = evt.target.value.split("\/");
                 field.value = resourceType[resourceType.length - 1];
             });
-         }
+        }
     });
     
     /* Support for repeating form fields */
@@ -54,4 +68,33 @@
             }
         }
     });
+    
+    
+    
+    nomnom.decorate('.richtext', {
+        callbacks : {
+            created : function(){
+                $(this).summernote({
+                    toolbar: [
+                        ['style', ['bold', 'italic', 'clear','strikethrough', 
'superscript', 'subscript']],
+                        ['insert', ['picture', 'link', 'table', 'hr']],
+                        ['para', ['style','ul', 'ol', 'paragraph']],
+                        ['misc', ['codeview', 'undo','redo','help']]
+                    ],
+                    followingToolbar: false,
+                    dialogsInBody: true,
+                    height: 200,
+                    onCreateLink: function (url) {
+                        return url;
+                    },
+                    callbacks: {
+                        onDialogShown: function(){
+                            Sling.CMS.ui.suggest($('.note-link-url')[0], 
'content', '/content');
+                            Sling.CMS.ui.suggest($('.note-image-url')[0], 
'content', '/content');
+                        }
+                    }
+                });
+            }
+        }
+    });
 }(window.nomnom = window.nomnom || {}));
\ No newline at end of file
diff --git a/ui/src/main/frontend/src/js/cms.modal.js 
b/ui/src/main/frontend/src/js/cms.modal.js
index 64d50a8..0cd813f 100644
--- a/ui/src/main/frontend/src/js/cms.modal.js
+++ b/ui/src/main/frontend/src/js/cms.modal.js
@@ -37,7 +37,7 @@
                 
                 var request = new XMLHttpRequest();
                 request.open('GET', link, true);
-                request.onload = function() {
+                request.onload = function () {
                     button.removeAttribute("disabled");
                     if 
(request.responseURL.indexOf('/system/sling/form/login?resource=') !== -1) {
                         window.location.reload();
@@ -47,7 +47,7 @@
                 };
                 request.send();
                 
-                
modal.querySelector('.delete,.close-modal').addEventListener("click", 
function(){
+                
modal.querySelector('.delete,.close-modal').addEventListener("click", function 
() {
                     modal.remove();
                     return false;
                 });
diff --git a/ui/src/main/frontend/src/js/cms.pathfield.js 
b/ui/src/main/frontend/src/js/cms.pathfield.js
index e3e2531..c54083f 100644
--- a/ui/src/main/frontend/src/js/cms.pathfield.js
+++ b/ui/src/main/frontend/src/js/cms.pathfield.js
@@ -17,14 +17,14 @@
  * under the License.
  */
 /* eslint-env browser, es6 */
-(function (nomnom) {
+(function (nomnom, Sling) {
     'use strict';
     var pathfield = null;
     nomnom.decorate("input.pathfield", {
-        callbacks :{
-            created : function(){
-                var type = this.dataset.type;
-                var base = this.dataset.base;
+        callbacks: {
+            created : function () {
+                var type = this.dataset.type,
+                    base = this.dataset.base;
                 Sling.CMS.ui.suggest(this, type, base);
             }
         }
@@ -45,4 +45,4 @@
         }
     });
     
-}(window.nomnom = window.nomnom || {}));
\ No newline at end of file
+}(window.nomnom = window.nomnom || {}, window.Sling = window.Sling || {}));
\ No newline at end of file
diff --git a/ui/src/main/frontend/src/js/cms.toggle.js 
b/ui/src/main/frontend/src/js/cms.toggle.js
index 3ac07be..9a2e6ca 100644
--- a/ui/src/main/frontend/src/js/cms.toggle.js
+++ b/ui/src/main/frontend/src/js/cms.toggle.js
@@ -1,43 +1,52 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-nomnom.decorate('.toggle-hidden' , {
-    events : {
-        click: function() {
-            $($(this).data('target')).toggleClass('is-hidden');
-        }
-    }
-});
-    
-nomnom.decorate('.toggle-value', {
-    callbacks : {
-        created :function(){
-            var source = this.getAttribute('data-toggle-source');
-            var selector = 'input[name="'+ source +'"], select[name="'+ source 
+'"]';
-            var $tog = $(this);
-            $(selector).change(function(){
-                if($(this).val() !== $tog.data('toggle-value')){
-                    $tog.addClass('is-hidden');
-                } else {
-                    $tog.removeClass('is-hidden');
-                }
-            });
-        }
-    }
-});
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* eslint-env browser, es6 */
+(function (nomnom) {
+    'use strict';
+    
+    nomnom.decorate('.toggle-hidden', {
+        events : {
+            click: function () {
+                var target = document.querySelectorAll(this.dataset.target);
+                target.forEach(function (el) {
+                    el.classList.toggle('is-hidden');
+                });
+            }
+        }
+    });
+
+    nomnom.decorate('.toggle-value', {
+        callbacks: {
+            created: function () {
+                var source = this.getAttribute('data-toggle-source'),
+                    selector = 'input[name="' + source + '"], select[name="' + 
source + '"]',
+                    toggle = this;
+                document.querySelector(selector).on('change', function () {
+                    if (this.value !== toggle.dataset.toggleValue) {
+                        toggle.classList.add('is-hidden');
+                    } else {
+                        toggle.classList.remove('is-hidden');
+                    }
+                });
+            }
+        }
+    });
+
+}(window.nomnom = window.nomnom || {}));
\ No newline at end of file
diff --git a/ui/src/main/frontend/src/js/cms.upload.js 
b/ui/src/main/frontend/src/js/cms.upload.js
deleted file mode 100644
index dd9a719..0000000
--- a/ui/src/main/frontend/src/js/cms.upload.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-nomnom.decorate(".file", {
-    events:{
-        input:{
-            change : function(event) {
-                var nameField = this.querySelector('.file-name');
-                if (nameField){
-                    nameField.textContent = event.target.files[0].name;
-                }
-            }
-        }
-    }
-});
\ No newline at end of file

Reply via email to