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 6cce518 Cleaning up some JS issues with the new library and migrating
a few more items off the old decorate method
6cce518 is described below
commit 6cce518812060d87a2efccfa793e24509d29e45c
Author: Dan Klco <[email protected]>
AuthorDate: Thu Oct 11 09:39:09 2018 -0400
Cleaning up some JS issues with the new library and migrating a few more
items off the old decorate method
---
ui/src/main/frontend/gulpfile.js | 14 +-
ui/src/main/frontend/src/js/cms.form.js | 12 +-
ui/src/main/frontend/src/js/cms.js | 176 +++++++-----------
ui/src/main/frontend/src/js/cms.taxonomy.js | 53 ++++++
ui/src/main/frontend/src/js/cms.toggle.js | 1 -
ui/src/main/frontend/src/js/editor.js | 206 +++++++++++----------
.../cms/pageproperties/pageproperties.jsp | 2 +-
7 files changed, 237 insertions(+), 227 deletions(-)
diff --git a/ui/src/main/frontend/gulpfile.js b/ui/src/main/frontend/gulpfile.js
index caa81eb..3720bee 100755
--- a/ui/src/main/frontend/gulpfile.js
+++ b/ui/src/main/frontend/gulpfile.js
@@ -88,20 +88,16 @@ gulp.task('cms-js', function() {
'./node_modules/summernote/dist/summernote-lite.js',
'./node_modules/js-autocomplete/auto-complete.js',
'./src/js/nomnom.js',
- './src/js/cms.nav.js',
- './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'
+ './src/js/cms.js',
+ './src/js/cms.*.js'
])
.pipe(uglify({
output: {
comments: saveLicense
}
- }).on('error', function (err) { log('[Error]' + err.toString());
exit(1); }))
+ }).on('error', function (err) {
+ log('[Error] ' + err.toString());
+ }))
.pipe(concat('scripts-all.min.js'))
.pipe(gulp.dest('./dist/jcr_root/static/clientlibs/sling-cms/js'));
});
diff --git a/ui/src/main/frontend/src/js/cms.form.js
b/ui/src/main/frontend/src/js/cms.form.js
index 789341d..925d939 100644
--- a/ui/src/main/frontend/src/js/cms.form.js
+++ b/ui/src/main/frontend/src/js/cms.form.js
@@ -52,8 +52,8 @@ nomnom.decorate(".Form-Ajax", class {
contentType: false,
dataType: 'json',
success: function(res,msg){
- if (callback && Sling.CMS.ext[callback]){
- Sling.CMS.ext[callback](res, msg);
+ if (callback && Sling.CMS.handlers[callback]){
+ Sling.CMS.handlers[callback](res, msg);
} else {
Sling.CMS.ui.confirmReload(res, msg);
}
@@ -76,7 +76,9 @@ nomnom.decorate(".Form-Ajax", class {
nomnom.decorate('.Get-Form', class {
- "submit::"(){
+ "submit::"(event){
+ event.preventDefault();
+ event.stopPropagation();
var $form = $(this);
var params = $form.serialize();
$form.find('.form-wrapper').attr('disabled', 'disabled');
@@ -89,8 +91,8 @@ nomnom.decorate('.Get-Form', class {
});
nomnom.decorate(".repeating", class {
-
- "click::.repeating__add"() {
+ "click::.repeating__add"(event) {
+ event.preventDefault();
var $rep = $(this);
var $div = $("<div/>").html($rep.find(".repeating__template").html());
$rep.find(".repeating__container").append($div);
diff --git a/ui/src/main/frontend/src/js/cms.js
b/ui/src/main/frontend/src/js/cms.js
index 33b8abb..89ce55b 100644
--- a/ui/src/main/frontend/src/js/cms.js
+++ b/ui/src/main/frontend/src/js/cms.js
@@ -28,6 +28,32 @@ Sling.CMS = {
}
}
},
+ handlers: {
+ handledelete: function(res, msg){
+ if(window.location.pathname.indexOf(res.path) !== -1){
+ window.top.Sling.CMS.ui.confirmMessage(msg,
res.title,function(){
+ window.location = '/cms';
+ });
+ } else {
+ Sling.CMS.ui.confirmReload(res, msg);
+ }
+ },
+ handlemove: function(res, msg){
+ var changes = res.changes[0];
+ if(changes.type === 'moved' &&
window.location.pathname.indexOf(changes.argument[0]) !== -1){
+ window.top.Sling.CMS.ui.confirmMessage(msg,
res.title,function(){
+ window.location =
window.location.href.replace(changes.argument[0], changes.argument[1]);
+ });
+ } else {
+ Sling.CMS.ui.confirmReload(res, msg);
+ }
+ },
+ handleugc: function(res, msg){
+ Sling.CMS.ui.confirmMessage(msg, res.title,function(){
+ window.location =
'/cms/usergenerated/content.html'+res.parentLocation;
+ });
+ }
+ },
init: function(){
for (var key in Sling.CMS.ext) {
if(typeof Sling.CMS.ext[key].init == 'function'){
@@ -72,70 +98,7 @@ Sling.CMS = {
}
}
};
-
- Sling.CMS.ext['handlemove'] = function(res, msg){
- var changes = res.changes[0];
- if(changes.type === 'moved' &&
window.location.pathname.indexOf(changes.argument[0]) !== -1){
- window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){
- window.location =
window.location.href.replace(changes.argument[0], changes.argument[1]);
- });
- } else {
- Sling.CMS.ui.confirmReload(res, msg);
- }
- }
-
- Sling.CMS.ext['handleugc'] = function(res, msg){
- Sling.CMS.ui.confirmMessage(msg, res.title,function(){
- window.location =
'/cms/usergenerated/content.html'+res.parentLocation;
- });
- }
-
- Sling.CMS.ext['namehint'] = {
- decorate: function($ctx){
- $ctx.find('.namehint').each(function(){
- var $nh = $(this);
-
$nh.parents('.Form-Ajax').find('select[name="sling:resourceType"]').change(function(){
- var resourceType = $(this).val().split("\/");
- $nh.val(resourceType[resourceType.length - 1]);
- });
- });
- }
- };
- Sling.CMS.ext['pageproperties'] = {
- decorate: function($ctx){
- $ctx.find('.Sling-CMS__page-properties').each(function(){
- var $ctr = $(this);
- var $wrapper = $ctr.closest('.form-wrapper');
- $($ctr.data('source')).change(function(){
- var config = $(this).val();
- $ctr.load($ctr.data('path')+config, function(){
- var source = $('#content-template').html();
- var template = Handlebars.compile(source);
- var updateContent = function(){
- if(!$wrapper.is(':disabled')){
- var data =
Sling.CMS.utils.form2Obj($ctr.parents('form'));
-
$('input[name=":content"]').val(template(data));
- }
- }
-
$ctr.find('input,textarea,select').change(updateContent);
- $ctr.parents('form').submit(updateContent);
- Sling.CMS.decorate($ctr.children());
- });
- });
- });
- }
- };
-
- Sling.CMS.ext['handledelete'] = function(res, msg){
- if(window.location.pathname.indexOf(res.path) !== -1){
- window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){
- window.location = '/cms';
- });
- } else {
- Sling.CMS.ui.confirmReload(res, msg);
- }
- }
Sling.CMS.ext['richtext'] = {
decorate: function($ctx){
@@ -176,6 +139,39 @@ Sling.CMS = {
$(document).ready(function() {
Sling.CMS.init();
});
+
+nomnom.decorate('.page-properties-container', class{
+ initCallback(){
+ var $ctr = $(this);
+ var $wrapper = $ctr.closest('.form-wrapper');
+ $($ctr.data('source')).change(function(){
+ var config = $(this).val();
+ $ctr.load($ctr.data('path')+config, function(){
+ var source = $('#content-template').html();
+ var template = Handlebars.compile(source);
+ var updateContent = function(){
+ if(!$wrapper.is(':disabled')){
+ var data =
Sling.CMS.utils.form2Obj($ctr.parents('form'));
+ $('input[name=":content"]').val(template(data));
+ }
+ }
+ $ctr.find('input,textarea,select').change(updateContent);
+ $ctr.parents('form').submit(updateContent);
+ Sling.CMS.decorate($ctr.children());
+ });
+ });
+ }
+});
+
+nomnom.decorate(".namehint",class {
+ initCallback(){
+ var $nh = $(this);
+
$nh.parents('.Form-Ajax').find('select[name="sling:resourceType"]').change(function(){
+ var resourceType = $(this).val().split("\/");
+ $nh.val(resourceType[resourceType.length - 1]);
+ });
+ }
+});
nomnom.decorate(".table .load-versions", class {
@@ -193,61 +189,23 @@ nomnom.decorate(".table .load-versions", class {
});
nomnom.decorate('.search-button', class {
-
- "click::listen"(event) {
- Sling.CMS.ext['searchbutton'] = Sling.CMS.ext['searchbutton'] || {};
- var searchbutton = Sling.CMS.ext['searchbutton'];
- searchbutton.active =
$(event.target).closest('.field').find('.pathfield');
+ "click::"(event) {
+ Sling.CMS.searchfield =
$($(event.target).closest('.field').find('.pathfield'));
}
-
});
nomnom.decorate('.search-select-button', class {
-
- "click::listen"(event) {
- var $btn = $(evt.target);
- var $active = Sling.CMS.ext['searchbutton'].active;
+ "click::"(event) {
+ event.stopPropagation();
+ event.preventDefault();
+ var $btn = $(event.target);
+ var $active = Sling.CMS.searchfield;
$active.val($btn.data('path'));
$btn.closest('.modal').remove();
}
-
});
-nomnom.decorate('.taxonomy', class {
- "click::listen"(){
- var $rep = $(this);
- $rep.find('.taxonomy__add').click(function(){
- var $span =
$('<span/>').html($rep.find('.taxonomy__template').html());
- var val = $ctx.find('.taxonomy__field input').val();
- var found = false;
- $rep.find('.taxonomy__item input').each(function(idx, el){
- if($(el).val() === val){
- found = true;
- }
- });
- if(found){
- return false;
- }
- $span.find('input').val(val);
- var title = $ctx.find('option[value="'+val+'"]').text();
-
- if(title !== ''){
- $span.find('.taxonomy__title').text(title);
- Sling.CMS.decorate($span);
- $('.taxonomy__container').append($span);
- $ctx.find('.taxonomy__field input').val('');
- }
- return false;
- });
- }
-});
-
-nomnom.decorate('.taxonomy__item', class {
- "click::listen"(){
- $(this).remove();
- return false;
- }
-});
+
nomnom.decorate(".table", class {
diff --git a/ui/src/main/frontend/src/js/cms.taxonomy.js
b/ui/src/main/frontend/src/js/cms.taxonomy.js
new file mode 100644
index 0000000..760cd85
--- /dev/null
+++ b/ui/src/main/frontend/src/js/cms.taxonomy.js
@@ -0,0 +1,53 @@
+/*
+ * 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('.taxonomy', class {
+ "click::.taxonomy__add"(event){
+ event.preventDefault();
+ event.stopPropagation();
+ var $ctx = $(this);
+ var $span = $('<span/>').html($ctx.find('.taxonomy__template').html());
+ var val = $ctx.find('.taxonomy__field input').val();
+ var found = false;
+ $ctx.find('.taxonomy__item input').each(function(idx, el){
+ if($(el).val() === val){
+ found = true;
+ }
+ });
+ if(found){
+ return false;
+ }
+ $span.find('input').val(val);
+ var title = $ctx.find('option[value="'+val+'"]').text();
+
+ if(title !== ''){
+ $span.find('.taxonomy__title').text(title);
+ Sling.CMS.decorate($span);
+ $('.taxonomy__container').append($span);
+ $ctx.find('.taxonomy__field input').val('');
+ }
+ return false;
+ }
+});
+
+nomnom.decorate('.taxonomy__item', class {
+ "click::"(){
+ $(this).remove();
+ return false;
+ }
+});
\ 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 10cea18..5a8a91b 100644
--- a/ui/src/main/frontend/src/js/cms.toggle.js
+++ b/ui/src/main/frontend/src/js/cms.toggle.js
@@ -22,7 +22,6 @@ nomnom.decorate('.toggle-hidden' , class {
$($(this).data('target')).toggleClass('is-hidden');
}
});
-
nomnom.decorate('.toggle-value', class {
initCallback(){
var source = this.getAttribute('data-toggle-source');
diff --git a/ui/src/main/frontend/src/js/editor.js
b/ui/src/main/frontend/src/js/editor.js
index 6b19b7f..1c62bf4 100644
--- a/ui/src/main/frontend/src/js/editor.js
+++ b/ui/src/main/frontend/src/js/editor.js
@@ -15,117 +15,119 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
-if(!window.CMSEditor){
- window.CMSEditor = {
- init: function(){
- CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=add]', function(evt){
-
CMSEditor.ui.showModal('/cms/editor/add.html'+this.dataset.slingCmsPath+'?availableTypes='+this.dataset.slingCmsAvailableTypes,
this.title);
- });
- CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=delete]', function(evt){
-
CMSEditor.ui.showModal('/cms/editor/delete.html'+this.dataset.slingCmsPath,
this.title);
- });
- CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=edit]', function(evt){
- CMSEditor.ui.showModal(
-
'/cms/editor/edit.html'+this.dataset.slingCmsPath+'?editor='+this.dataset.slingCmsEdit,
-
CMSEditor.util.findParent(this,'.sling-cms-component').dataset.slingCmsTitle ||
this.title);
- });
- CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=reorder]', function(evt){
-
CMSEditor.ui.showModal('/cms/editor/reorder.html'+this.dataset.slingCmsPath,
this.title);
- });
-
- // closing the modal
- CMSEditor.util.attachClick('.sling-cms-editor .close-modal',
function(){
- CMSEditor.ui.hideModal();
- });
- window.addEventListener('keypress',function(e){
- if(e.keyCode==27 && CMSEditor.ui.modalDisplayed === true){
- CMSEditor.ui.hideModal();
- }
- });
-
- var mouseX;
- var mouseY;
-
- function draggable(element) {
- var mouseDown = false;
- var elementX = 0;
- var elementY = 0;
+ */
+/* eslint-env browser */
+(function () {
+ 'use strict';
+ if (!window.CMSEditor) {
+ var CMSEditor = {
+ init: function () {
+ CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=add]', function () {
+ CMSEditor.ui.showModal('/cms/editor/add.html' +
this.dataset.slingCmsPath + '?availableTypes=' +
this.dataset.slingCmsAvailableTypes, this.title);
+ });
+ CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=delete]', function () {
+ CMSEditor.ui.showModal('/cms/editor/delete.html' +
this.dataset.slingCmsPath, this.title);
+ });
+ CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=edit]', function () {
+ CMSEditor.ui.showModal(
+ '/cms/editor/edit.html' + this.dataset.slingCmsPath +
'?editor=' + this.dataset.slingCmsEdit,
+ CMSEditor.util.findParent(this,
'.sling-cms-component').dataset.slingCmsTitle || this.title
+ );
+ });
+ CMSEditor.util.attachClick('.sling-cms-editor
.button[data-sling-cms-action=reorder]', function () {
+ CMSEditor.ui.showModal('/cms/editor/reorder.html' +
this.dataset.slingCmsPath, this.title);
+ });
- // mouse button down over the element
- element.addEventListener('mousedown', function(evt){
- if(evt.target.matches('.modal-card-body *')){
- return;
- }
- mouseX = evt.clientX;
- mouseY = evt.clientY;
- mouseDown = true;
+ // closing the modal
+ CMSEditor.util.attachClick('.sling-cms-editor .close-modal',
function () {
+ CMSEditor.ui.hideModal();
});
-
- var moveComplete = function(evt){
- mouseDown = false;
- elementX = parseInt(element.style.left) || 0;
- elementY = parseInt(element.style.top) || 0;
- return false;
- }
-
- element.addEventListener('mouseup', moveComplete);
- document.addEventListener('mouseout', moveComplete);
-
- document.addEventListener('mousemove', function(event) {
- if (!mouseDown) {
- return;
+ window.addEventListener('keypress', function (e) {
+ if (e.keyCode === 27 && CMSEditor.ui.modalDisplayed ===
true) {
+ CMSEditor.ui.hideModal();
}
- var deltaX = event.clientX - mouseX;
- var deltaY = event.clientY - mouseY;
- element.style.left = elementX + deltaX + 'px';
- element.style.top = elementY + deltaY + 'px';
- return false;
});
- }
- draggable(document.querySelector('.sling-cms-editor .modal-card'));
- },
- ui: {
- modalDisplayed: false,
- hideModal: function() {
- if(CMSEditor.ui.modalDisplayed) {
- document.querySelector('.sling-cms-editor
.modal').classList.remove('is-active');
- CMSEditor.ui.modalDisplayed = false;
+
+ var mouseX, mouseY;
+
+ function draggable(element) {
+ var mouseDown = false, elementX = 0, elementY = 0;
+
+ // mouse button down over the element
+ element.addEventListener('mousedown', function (evt) {
+ if (evt.target.matches('.modal-card-body *')) {
+ return;
+ }
+ mouseX = evt.clientX;
+ mouseY = evt.clientY;
+ mouseDown = true;
+ });
+
+ var moveComplete = function () {
+ mouseDown = false;
+ elementX = parseInt(element.style.left, 10) || 0;
+ elementY = parseInt(element.style.top, 10) || 0;
+ return false;
+ };
+
+ element.addEventListener('mouseup', moveComplete);
+ document.addEventListener('mouseout', moveComplete);
+
+ document.addEventListener('mousemove', function (event) {
+ if (!mouseDown) {
+ return;
+ }
+ var deltaX = event.clientX - mouseX, deltaY =
event.clientY - mouseY;
+ element.style.left = elementX + deltaX + 'px';
+ element.style.top = elementY + deltaY + 'px';
+ return false;
+ });
}
+ draggable(document.querySelector('.sling-cms-editor
.modal-card'));
},
- showModal: function(url, title){
- title = title || '';
- if(CMSEditor.ui.modalDisplayed) {
- CMSEditor.ui.hideModal();
- }
- document.querySelector('.sling-cms-editor
.modal-card-title').innerText = title;
- document.querySelector('.sling-cms-editor
.modal-card-body').innerHTML = '<iframe class="modal-frame"
src="'+url+'"></iframe>';
- document.querySelector('.sling-cms-editor
.modal').classList.add('is-active');
+ ui: {
+ modalDisplayed: false,
+ hideModal: function () {
+ if (CMSEditor.ui.modalDisplayed) {
+ document.querySelector('.sling-cms-editor
.modal').classList.remove('is-active');
+ CMSEditor.ui.modalDisplayed = false;
+ }
+ },
+ showModal: function (url, title) {
+ title = title || '';
+ if (CMSEditor.ui.modalDisplayed) {
+ CMSEditor.ui.hideModal();
+ }
+ document.querySelector('.sling-cms-editor
.modal-card-title').innerText = title;
+ document.querySelector('.sling-cms-editor
.modal-card-body').innerHTML = '<iframe class="modal-frame" src="' + url +
'"></iframe>';
+ document.querySelector('.sling-cms-editor
.modal').classList.add('is-active');
- CMSEditor.ui.modalDisplayed = true;
- }
- },
- util: {
- attachClick: function(exp, cb){
- document.querySelectorAll(exp).forEach(function(el){
- el.addEventListener('click', cb, false);
- });
+ CMSEditor.ui.modalDisplayed = true;
+ }
},
- findParent: function(el,exp){
- if(el == null || el.parentElement == null){
- return null
- } else if(el.parentElement.matches(exp)){
- return el.parentElement;
- } else {
- return CMSEditor.util.findParent(el.parentElement, exp);
+ util: {
+ attachClick: function (exp, cb) {
+ document.querySelectorAll(exp).forEach(function (el) {
+ el.addEventListener('click', cb, false);
+ });
+ },
+ findParent: function (el, exp) {
+ if (el === null || el.parentElement === null) {
+ return null;
+ } else if (el.parentElement.matches(exp)) {
+ return el.parentElement;
+ } else {
+ return CMSEditor.util.findParent(el.parentElement,
exp);
+ }
}
}
+ };
+ window.CMSEditor = CMSEditor;
+
+ if (document.readyState === 'complete') {
+ window.CMSEditor.init();
+ } else {
+ document.addEventListener('DOMContentLoaded', CMSEditor.init,
false);
}
}
-
- if (document.readyState === 'complete') {
- CMSEditor.init();
- } else {
- document.addEventListener('DOMContentLoaded',CMSEditor.init,false);
- }
-}
\ No newline at end of file
+}());
\ No newline at end of file
diff --git
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/pageproperties.jsp
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/pageproperties.jsp
index 7e65828..d5e270d 100644
---
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/pageproperties.jsp
+++
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/pageproperties.jsp
@@ -17,7 +17,7 @@
* under the License.
*/ --%>
<%@include file="/libs/sling-cms/global.jsp"%>
-<div class="Sling-CMS__page-properties"
data-path="${resource.path}.include.html"
data-source="select[name=pageTemplate]">
+<div class="page-properties-container"
data-path="${resource.path}.include.html"
data-source="select[name=pageTemplate]">
</div>
<input type="hidden" name=":operation" value="import" />
<input type="hidden" name=":replaceProperties" value="true" />