Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karten auf CMB2 umstellen #1413

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ module.exports = function (grunt) {
],
tasks: [
'dart-sass:adminDev', 'dart-sass:publicDev'
]
],
options: {
livereload: true
}
},
js: {
files: [
Expand Down
92 changes: 92 additions & 0 deletions assets/admin/js/src/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
(function ($) {
'use strict';
$(function () {
const mapSettingsForm = $("#cmb2-metabox-cb_map-custom-fields");

const hideFieldset = function (set) {
$.each(set, function () {
$(this).parents('.cmb-row').hide();
});
};

/**
* Show set-elements.
* @param set
*/
const showFieldset = function (set) {
$.each(set, function () {
$(this).parents('.cmb-row').show();
});
};

const copyToClipboard = function (element) {
let code = $(element).find('code')[0];
let text = code.innerText;
navigator.clipboard.writeText(text).then(function () {
let button = $(element).find('.button');
let buttonText = button.text();
button.text('✓');
button.disabled = true;
setTimeout(function () {
button.text(buttonText);
button.disabled = false;
}, 2000);
});
}

const copyToClipboardButton = $('#shortcode-field').find('.button');
copyToClipboardButton.on('click', function () {
debugger;
copyToClipboard($('#shortcode-field'));
});

function handleCustomFileInput(fileSelectorID, fileInputFields) {
const markerFileSelect = document.querySelector(fileSelectorID);
const handleSelectCustomMarker = function () {
showFieldset(fileInputFields);
if (markerFileSelect.value === '') {
hideFieldset(fileInputFields);
}
};

handleSelectCustomMarker();

const observerConfig = {attributes: true, childList: false, subtree: false};
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.attributeName === 'value') {
handleSelectCustomMarker();
}
});
});
observer.observe(markerFileSelect, observerConfig);
}

if (mapSettingsForm.length) {
handleCustomFileInput(
'#custom_marker_media',
[
$('#marker_icon_width'),
$('#marker_icon_height'),
$('#marker_icon_anchor_x'),
$('#marker_icon_anchor_y')
]);
handleCustomFileInput(
'#custom_marker_cluster_media',
[
$('#marker_cluster_icon_width'),
$('#marker_cluster_icon_height')
]
);
handleCustomFileInput(
'#marker_item_draft_media',
[
$('#marker_item_draft_icon_width'),
$('#marker_item_draft_icon_height'),
$('#marker_item_draft_icon_anchor_x'),
$('#marker_item_draft_icon_anchor_y')
]
);
}
});
})(jQuery);
5 changes: 4 additions & 1 deletion assets/admin/sass/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
/* Booking form */
@import "./partials/form-booking";

/* Booking form */
/* Map creation */
@import "./partials/form-map";

/* Plugin update page */
@import "./partials/plugin_update";

/* Edit Screens Backend */
Expand Down
41 changes: 41 additions & 0 deletions assets/admin/sass/partials/_form-map.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* The CPT creation form map
*/

#cmb2-metabox-cb_map-custom-fields {
.map-organizer {
.cmb2-metabox-title {
font-size: x-large;
}
.cmb2-metabox-title:before {
/* arrow to right */
content: "\2192 ";
}
}

.cmb-group-name {
font-size: x-large;
font-weight: bold;
}

.cmb-group-name:before {
content: "\2192 ";
}

#shortcode-field {
display: flex;
align-items: center;
flex-wrap: nowrap;
gap: 10px;
}

#shortcode-field code {
white-space: nowrap;
margin-right: 10px;
}

#shortcode-field .button {
padding: 5px 10px;
line-height: 1.5;
}
}
169 changes: 0 additions & 169 deletions assets/map/js/cb-map-marker-upload.js

This file was deleted.

7 changes: 0 additions & 7 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ function commonsbooking_admin() {
);
}

// Map marker upload scripts
// TODO needs to be evaluated. Maybe not working on all systems
if ( get_current_screen()->id == 'cb_map' ) {
$script_path = COMMONSBOOKING_MAP_ASSETS_URL . 'js/cb-map-marker-upload.js';
wp_enqueue_script( 'cb-map-marker-upload_js', $script_path );
}

// CB 0.X migration
wp_localize_script(
'cb-scripts-admin',
Expand Down
Loading