mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
improve field add on frontmatter
This commit is contained in:
parent
26c89f1fce
commit
c81c1d3bf1
2
assets/js/app.min.js
vendored
2
assets/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
@ -119,21 +119,16 @@ $(document).on('page:editor', function() {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
defaultID = "lorem-ipsum-sin-dolor-amet";
|
defaultID = "lorem-ipsum-sin-dolor-amet";
|
||||||
|
|
||||||
if ($("#" + defaultID).length) {
|
// Remove if there is an incomplete new item
|
||||||
return false;
|
newItem = $("#" + defaultID);
|
||||||
|
if (newItem.length) {
|
||||||
|
newItem.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
block = $(this).parent().parent();
|
block = $(this).parent().parent();
|
||||||
blockType = block.data("type");
|
blockType = block.data("type");
|
||||||
blockID = block.attr("id");
|
blockID = block.attr("id");
|
||||||
|
|
||||||
// Main add button, after all blocks
|
|
||||||
if (block.is('div') && block.hasClass("frontmatter")) {
|
|
||||||
block = $('.blocks');
|
|
||||||
block.append('<div class="block" id="' + defaultID + '"></div>');
|
|
||||||
blockType = "object";
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Block Type is an array
|
// If the Block Type is an array
|
||||||
if (blockType == "array") {
|
if (blockType == "array") {
|
||||||
newID = blockID + "[]";
|
newID = blockID + "[]";
|
||||||
@ -141,15 +136,19 @@ $(document).on('page:editor', function() {
|
|||||||
input = input.replace(/\[/, '\\[');
|
input = input.replace(/\[/, '\\[');
|
||||||
input = input.replace(/\]/, '\\]');
|
input = input.replace(/\]/, '\\]');
|
||||||
block.append('<div id="' + newID + '-' + $('#' + input + ' > div').length + '" data-type="array-item"><input name="' + newID + ':auto" id="' + newID + '"></input><span class="actions"> <button class="delete">−</button></span></div></div>');
|
block.append('<div id="' + newID + '-' + $('#' + input + ' > div').length + '" data-type="array-item"><input name="' + newID + ':auto" id="' + newID + '"></input><span class="actions"> <button class="delete">−</button></span></div></div>');
|
||||||
|
console.log('New array item added.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockType == "object" && !block.hasClass("frontmatter")) {
|
// Main add button, after all blocks
|
||||||
block.append('<div class="block" id="' + defaultID + '"></div>');
|
if (block.is('div') && block.hasClass("frontmatter")) {
|
||||||
|
block = $('.blocks');
|
||||||
blockType = "object";
|
blockType = "object";
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the Block is an object
|
// If the Block is an object
|
||||||
if (blockType == "object") {
|
if (blockType == "object") {
|
||||||
|
block.append('<div class="block" id="' + defaultID + '"></div>');
|
||||||
|
|
||||||
newItem = $("#" + defaultID);
|
newItem = $("#" + defaultID);
|
||||||
newItem.html('<input id="name-' + defaultID + '" placeholder="Write the field name and press enter..."></input>');
|
newItem.html('<input id="name-' + defaultID + '" placeholder="Write the field name and press enter..."></input>');
|
||||||
field = $("#name-" + defaultID);
|
field = $("#name-" + defaultID);
|
||||||
@ -167,7 +166,6 @@ $(document).on('page:editor', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(field).keypress(function(event) {
|
$(field).keypress(function(event) {
|
||||||
console.log('got it');
|
|
||||||
// When you press enter within the new name field:
|
// When you press enter within the new name field:
|
||||||
if (event.which == 13) {
|
if (event.which == 13) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user