进行了一些小修复
This commit is contained in:
1 parent
992af2119d
commit
2cb78edabb
26 files changed
+2091
-2383
No files matched your search
@@ -0,0 +1,136 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var root = document.querySelector('[data-aksrt-pay-meta]');
|
||||
if (!root) return;
|
||||
|
||||
function selected(name) {
|
||||
var input = root.querySelector('input[name="aksrt_pay[' + name + ']"]:checked');
|
||||
return input ? input.value : '';
|
||||
}
|
||||
|
||||
function syncDependencies() {
|
||||
var type = selected('pay_type');
|
||||
var modo = selected('pay_modo');
|
||||
var enabled = type !== 'no';
|
||||
var enabledBox = root.querySelector('[data-pay-enabled]');
|
||||
if (enabledBox) enabledBox.hidden = !enabled;
|
||||
|
||||
root.querySelectorAll('[data-pay-type]').forEach(function (field) {
|
||||
field.hidden = field.getAttribute('data-pay-type') !== type;
|
||||
});
|
||||
root.querySelectorAll('[data-pay-modo]').forEach(function (field) {
|
||||
field.hidden = field.getAttribute('data-pay-modo') !== modo;
|
||||
});
|
||||
|
||||
var expired = root.querySelector('[data-order-expired]');
|
||||
var expiredFields = root.querySelector('[data-order-expired-fields]');
|
||||
if (expiredFields) expiredFields.hidden = !expired || !expired.checked;
|
||||
}
|
||||
|
||||
function openMedia(button) {
|
||||
if (!window.wp || !wp.media) return;
|
||||
var wrap = button.closest('.aksrt-pay-meta__upload');
|
||||
var input = wrap && wrap.querySelector('[data-media-input]');
|
||||
if (!input) return;
|
||||
var library = button.getAttribute('data-library') || '';
|
||||
var options = { title: library === 'video' ? '选择视频' : '选择文件', multiple: false };
|
||||
if (library) options.library = { type: library };
|
||||
var frame = wp.media(options);
|
||||
frame.on('select', function () {
|
||||
var item = frame.state().get('selection').first().toJSON();
|
||||
input.value = item.url || '';
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
});
|
||||
frame.open();
|
||||
}
|
||||
|
||||
function renderGallery() {
|
||||
if (!window.wp || !wp.media) return;
|
||||
var input = root.querySelector('[data-gallery-input]');
|
||||
var preview = root.querySelector('[data-gallery-preview]');
|
||||
if (!input || !preview) return;
|
||||
preview.innerHTML = '';
|
||||
input.value.split(',').map(function (id) { return parseInt(id, 10); }).filter(Boolean).forEach(function (id) {
|
||||
wp.media.attachment(id).fetch().then(function () {
|
||||
var data = wp.media.attachment(id).toJSON();
|
||||
var image = document.createElement('img');
|
||||
image.src = (data.sizes && data.sizes.thumbnail ? data.sizes.thumbnail.url : data.url) || '';
|
||||
image.alt = data.alt || '';
|
||||
preview.appendChild(image);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function openGallery() {
|
||||
if (!window.wp || !wp.media) return;
|
||||
var input = root.querySelector('[data-gallery-input]');
|
||||
if (!input) return;
|
||||
var frame = wp.media({ title: '新增图片', library: { type: 'image' }, multiple: true });
|
||||
frame.on('open', function () {
|
||||
input.value.split(',').map(function (id) { return parseInt(id, 10); }).filter(Boolean).forEach(function (id) {
|
||||
frame.state().get('selection').add(wp.media.attachment(id));
|
||||
});
|
||||
});
|
||||
frame.on('select', function () {
|
||||
input.value = frame.state().get('selection').map(function (item) { return item.id; }).join(',');
|
||||
renderGallery();
|
||||
});
|
||||
frame.open();
|
||||
}
|
||||
|
||||
function addGroup(button) {
|
||||
var id = button.getAttribute('data-group-add');
|
||||
var list = root.querySelector('[data-group-list="' + id + '"]');
|
||||
var template = root.querySelector('[data-group-template="' + id + '"]');
|
||||
if (!list || !template) return;
|
||||
var index = list.querySelectorAll('[data-group-row]').length;
|
||||
list.insertAdjacentHTML('beforeend', template.innerHTML.replaceAll('__INDEX__', String(index)));
|
||||
}
|
||||
|
||||
root.addEventListener('click', function (event) {
|
||||
var target = event.target;
|
||||
var media = target.closest('[data-media-select]');
|
||||
if (media) {
|
||||
event.preventDefault();
|
||||
openMedia(media);
|
||||
return;
|
||||
}
|
||||
var clear = target.closest('[data-media-clear]');
|
||||
if (clear) {
|
||||
event.preventDefault();
|
||||
var wrap = clear.closest('.aksrt-pay-meta__upload');
|
||||
var input = wrap && wrap.querySelector('[data-media-input]');
|
||||
if (input) input.value = '';
|
||||
return;
|
||||
}
|
||||
if (target.closest('[data-gallery-select]')) {
|
||||
event.preventDefault();
|
||||
openGallery();
|
||||
return;
|
||||
}
|
||||
if (target.closest('[data-gallery-clear]')) {
|
||||
event.preventDefault();
|
||||
var gallery = root.querySelector('[data-gallery-input]');
|
||||
if (gallery) gallery.value = '';
|
||||
renderGallery();
|
||||
return;
|
||||
}
|
||||
var add = target.closest('[data-group-add]');
|
||||
if (add) {
|
||||
event.preventDefault();
|
||||
addGroup(add);
|
||||
return;
|
||||
}
|
||||
var remove = target.closest('[data-group-remove]');
|
||||
if (remove) {
|
||||
event.preventDefault();
|
||||
var row = remove.closest('[data-group-row]');
|
||||
if (row) row.remove();
|
||||
}
|
||||
});
|
||||
|
||||
root.addEventListener('change', syncDependencies);
|
||||
renderGallery();
|
||||
syncDependencies();
|
||||
})();
|
||||
@@ -0,0 +1,123 @@
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
var root = document.querySelector('[data-aksrt-post-extension]');
|
||||
if (!root || !window.wp || !wp.media) return;
|
||||
|
||||
function openMedia(button) {
|
||||
var wrap = button.closest('.aksrt-post-extension__upload');
|
||||
var input = wrap && wrap.querySelector('[data-media-input]');
|
||||
if (!input) return;
|
||||
|
||||
var library = button.getAttribute('data-library') || 'image';
|
||||
var frame = wp.media({
|
||||
title: library === 'video' ? '选择视频' : '选择图像',
|
||||
library: { type: library },
|
||||
multiple: false
|
||||
});
|
||||
frame.on('select', function () {
|
||||
var item = frame.state().get('selection').first().toJSON();
|
||||
input.value = item.url || '';
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
});
|
||||
frame.open();
|
||||
}
|
||||
|
||||
function renderGallery() {
|
||||
var input = root.querySelector('[data-gallery-input]');
|
||||
var preview = root.querySelector('[data-gallery-preview]');
|
||||
if (!input || !preview) return;
|
||||
|
||||
preview.innerHTML = '';
|
||||
var ids = input.value.split(',').map(function (id) { return parseInt(id, 10); }).filter(Boolean);
|
||||
ids.forEach(function (id) {
|
||||
wp.media.attachment(id).fetch().then(function () {
|
||||
var data = wp.media.attachment(id).toJSON();
|
||||
var img = document.createElement('img');
|
||||
img.src = (data.sizes && data.sizes.thumbnail ? data.sizes.thumbnail.url : data.url) || '';
|
||||
img.alt = data.alt || '';
|
||||
preview.appendChild(img);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function openGallery() {
|
||||
var input = root.querySelector('[data-gallery-input]');
|
||||
if (!input) return;
|
||||
var frame = wp.media({ title: '添加图像', library: { type: 'image' }, multiple: true });
|
||||
frame.on('open', function () {
|
||||
input.value.split(',').map(function (id) { return parseInt(id, 10); }).filter(Boolean).forEach(function (id) {
|
||||
frame.state().get('selection').add(wp.media.attachment(id));
|
||||
});
|
||||
});
|
||||
frame.on('select', function () {
|
||||
input.value = frame.state().get('selection').map(function (item) { return item.id; }).join(',');
|
||||
renderGallery();
|
||||
});
|
||||
frame.open();
|
||||
}
|
||||
|
||||
function syncVideoDependencies() {
|
||||
var input = root.querySelector('input[name="aksrt_post_extension[featured_video]"]');
|
||||
root.querySelectorAll('[data-video-dependent]').forEach(function (field) {
|
||||
field.hidden = !input || !input.value.trim();
|
||||
});
|
||||
}
|
||||
|
||||
root.addEventListener('click', function (event) {
|
||||
var mediaButton = event.target.closest('[data-media-select]');
|
||||
if (mediaButton) {
|
||||
event.preventDefault();
|
||||
openMedia(mediaButton);
|
||||
return;
|
||||
}
|
||||
|
||||
var clear = event.target.closest('[data-media-clear]');
|
||||
if (clear) {
|
||||
event.preventDefault();
|
||||
var wrap = clear.closest('.aksrt-post-extension__upload');
|
||||
var input = wrap && wrap.querySelector('[data-media-input]');
|
||||
if (input) {
|
||||
input.value = '';
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.closest('[data-gallery-select]')) {
|
||||
event.preventDefault();
|
||||
openGallery();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.closest('[data-gallery-clear]')) {
|
||||
event.preventDefault();
|
||||
var galleryInput = root.querySelector('[data-gallery-input]');
|
||||
if (galleryInput) galleryInput.value = '';
|
||||
renderGallery();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.closest('[data-episode-add]')) {
|
||||
event.preventDefault();
|
||||
var list = root.querySelector('[data-episode-list]');
|
||||
var template = root.querySelector('[data-episode-template]');
|
||||
if (!list || !template) return;
|
||||
var index = list.querySelectorAll('[data-episode-row]').length;
|
||||
list.insertAdjacentHTML('beforeend', template.innerHTML.replaceAll('__INDEX__', String(index)));
|
||||
return;
|
||||
}
|
||||
|
||||
var remove = event.target.closest('[data-episode-remove]');
|
||||
if (remove) {
|
||||
event.preventDefault();
|
||||
var row = remove.closest('[data-episode-row]');
|
||||
if (row) row.remove();
|
||||
}
|
||||
});
|
||||
|
||||
root.addEventListener('input', syncVideoDependencies);
|
||||
root.addEventListener('change', syncVideoDependencies);
|
||||
renderGallery();
|
||||
syncVideoDependencies();
|
||||
})(jQuery);
|
||||
+27
-10
@@ -110,6 +110,7 @@
|
||||
this.bindLeaveWarning();
|
||||
this.bindAi();
|
||||
this.bindTagActive();
|
||||
this.bindDropSelect();
|
||||
this.loadFeaturedFromDom();
|
||||
},
|
||||
|
||||
@@ -160,11 +161,12 @@
|
||||
},
|
||||
|
||||
bindTagActive: function () {
|
||||
qsa('.aksrt-submit-tag input').forEach(function (input) {
|
||||
qsa('.aksrt-submit-tag input, .newpost-filter-tags input').forEach(function (input) {
|
||||
var sync = function () {
|
||||
var tag = input.closest('.aksrt-submit-tag');
|
||||
var tag = input.closest('.aksrt-submit-tag, .tag-list');
|
||||
if (tag) {
|
||||
tag.classList.toggle('is-active', input.checked);
|
||||
tag.classList.toggle('active', input.checked);
|
||||
}
|
||||
};
|
||||
input.addEventListener('change', sync);
|
||||
@@ -172,6 +174,18 @@
|
||||
});
|
||||
},
|
||||
|
||||
bindDropSelect: function () {
|
||||
qsa('.term-select-box [data-toggle-class="open"]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
var box = button.closest('.drop-select');
|
||||
if (!box) return;
|
||||
var open = !box.classList.contains('open');
|
||||
box.classList.toggle('open', open);
|
||||
button.setAttribute('aria-expanded', open ? 'true' : 'false');
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
bindSubmitButtons: function () {
|
||||
var self = this;
|
||||
qsa('.aksrt-submit-btn', this.form).forEach(function (btn) {
|
||||
@@ -393,11 +407,7 @@
|
||||
|
||||
setFeatured: function (type, data) {
|
||||
this.featured = { type: type || '', data: data || {} };
|
||||
var typeInput = qs('[data-featured-type]');
|
||||
var jsonInput = qs('[data-featured-json]');
|
||||
if (typeInput) {
|
||||
typeInput.value = type || '';
|
||||
}
|
||||
if (jsonInput) {
|
||||
jsonInput.value = JSON.stringify(this.featured);
|
||||
}
|
||||
@@ -412,6 +422,13 @@
|
||||
}
|
||||
var t = this.featured.type;
|
||||
var d = this.featured.data || {};
|
||||
var box = qs('.featured-edit');
|
||||
if (box) {
|
||||
box.classList.remove('featured-loaded', 'image', 'slide', 'video');
|
||||
if (t && t !== 'close') {
|
||||
box.classList.add('featured-loaded', t);
|
||||
}
|
||||
}
|
||||
var html = '';
|
||||
if (t === 'image' && d.url) {
|
||||
html = '<img src="' + d.url + '" alt="">';
|
||||
@@ -419,15 +436,15 @@
|
||||
html =
|
||||
'<img src="' +
|
||||
d[0].url +
|
||||
'" alt=""><span class="aksrt-submit-featured__badge"><i class="fa fas fa-image"></i></span>';
|
||||
'" alt=""><span class="featured-type-badge"><i class="fa fas fa-image"></i></span>';
|
||||
} else if (t === 'video') {
|
||||
html =
|
||||
(d.pic
|
||||
? '<img src="' + d.pic + '" alt="">'
|
||||
: '<div class="aksrt-submit-featured__video-placeholder"><i class="fa fas fa-play"></i></div>') +
|
||||
'<span class="aksrt-submit-featured__badge"><i class="fa fas fa-video"></i></span>';
|
||||
: '<div class="featured-video-placeholder"><i class="fa fas fa-play"></i></div>') +
|
||||
'<span class="featured-type-badge"><i class="fa fas fa-video"></i></span>';
|
||||
} else {
|
||||
html = '<div class="aksrt-submit-featured__empty"><i class="fa fas fa-image"></i><span>Cover</span></div>';
|
||||
html = '<div class="featured-empty"><i class="fa fas fa-image"></i><span>设置文章封面</span></div>';
|
||||
}
|
||||
preview.innerHTML = html;
|
||||
var clearBtn = qs('[data-featured-action="close"]');
|
||||
|
||||
Reference in new issue
Block a user