본문으로 이동

미디어위키:Gadget-MetadataEditor.js: 두 판 사이의 차이

리버티게임(개발), 모두가 만들어가는 자유로운 게임
Senouis (토론 | 기여)
잔글편집 요약 없음
Senouis (토론 | 기여)
잔글편집 요약 없음
1번째 줄: 1번째 줄:
var metadata_schema;


function LoadJSONEditor(targetJSON) {
const addJSONEditor = () => {
  if (document.getElementsByClassName("jsoneditor-container").length === 0) return;
if (document.getElementsByClassName("jsoneditor-container").length === 0) return;
  mw.loader.getScript("https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js").then(function() {
mw.loader.getScript("https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js").then(function() {
     fetch("https://dev.libertygame.work/index.php/%EB%A6%AC%EB%B2%84%ED%8B%B0%EA%B2%8C%EC%9E%84:%EA%B2%8C%EC%9E%84_%EB%A9%94%ED%83%80%EB%8D%B0%EC%9D%B4%ED%84%B0/%EC%8A%A4%ED%82%A4%EB%A7%88.json?action=raw")
     fetch("https://dev.libertygame.work/index.php/%EB%A6%AC%EB%B2%84%ED%8B%B0%EA%B2%8C%EC%9E%84:%EA%B2%8C%EC%9E%84_%EB%A9%94%ED%83%80%EB%8D%B0%EC%9D%B4%ED%84%B0/%EC%8A%A4%ED%82%A4%EB%A7%88.json?action=raw")
     .then(function(result){return result.json(); })
     .then(function(result){return result.json(); })
9번째 줄: 10번째 줄:
  jsonEditorContainer.style.display = "block";
  jsonEditorContainer.style.display = "block";
  const editorvalue = document.querySelector('#value');
  const editorvalue = document.querySelector('#value');
  metadata_schema = result;
  var schema = result;
  fetch(targetJSON).then(function(result){return result.json(); }).then(function (response) {
  const editor = new JSONEditor(jsonEditorContainer, {
  mode: 'tree',
    schema: schema,
    theme: 'tailwind',
    iconlib: 'openiconic',
    keep_oneof_values: false,
    disable_edit_json: true
  }, response);
  editor.on('change', function () {
    editorvalue.value = JSON.stringify(editor.getValue(), null, 2);
  });
 
  }).catch('JSON 에디터 로딩 후 JSON 타겟 가져오기 실패');
  }).catch(function (e) {
  }).catch(function (e) {
  console.log("JSON 에디터 로딩 중 장애 발생" + e.message);
  console.log("JSON 에디터 로딩 중 장애 발생" + e.message);
  });
  });
   });
   });
}
const addJSONEditor = () => {
let metadataTab = document.getElementById("metadata-namevalue");
let metadataTab = document.getElementById("metadata-namevalue");
metadataTab.addEventListener('click', (ev) => {
a.addEventListener('click', (ev) => {
console.log(mw.config.get("wgPageName"));
console.log(mw.config.get("wgPageName"));
var targetJSON = "https://dev.libertygame.work/index.php/RPG_in_City/game.json?action=raw";
var targetJSON = "https://dev.libertygame.work/index.php/RPG_in_City/game.json?action=raw";
LoadJSONEditor(targetJSON);
fetch(targetJSON).then(function(result){return result.json(); }).then(function (response) {
  const editor = new JSONEditor(jsonEditorContainer, {
  mode: 'tree',
    schema: schema,
    theme: 'tailwind',
    iconlib: 'openiconic',
    keep_oneof_values: false,
    disable_edit_json: true
  }, response);
  editor.on('change', function () {
    editorvalue.value = JSON.stringify(editor.getValue(), null, 2);
  });
 
  }).catch('JSON 에디터 로딩 후 JSON 타겟 가져오기 실패');
});
});
document.getElementById("value").addEventListener('change', (ev) => {
document.getElementById("value").addEventListener('change', (ev) => {

2025년 1월 27일 (월) 17:55 판

var metadata_schema;

const addJSONEditor = () => {
	if (document.getElementsByClassName("jsoneditor-container").length === 0) return;
	mw.loader.getScript("https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js").then(function() {
  	  fetch("https://dev.libertygame.work/index.php/%EB%A6%AC%EB%B2%84%ED%8B%B0%EA%B2%8C%EC%9E%84:%EA%B2%8C%EC%9E%84_%EB%A9%94%ED%83%80%EB%8D%B0%EC%9D%B4%ED%84%B0/%EC%8A%A4%ED%82%A4%EB%A7%88.json?action=raw")
  	  .then(function(result){return result.json(); })
  	  .then(function (result) {
		  const jsonEditorContainer = document.querySelector('.json-editor-container');
		  jsonEditorContainer.style.display = "block";
		  const editorvalue = document.querySelector('#value');
		  metadata_schema = result;
	  }).catch(function (e) {
	  	console.log("JSON 에디터 로딩 중 장애 발생" + e.message);
	  });
  });
	let metadataTab = document.getElementById("metadata-namevalue");
	a.addEventListener('click', (ev) => {
		console.log(mw.config.get("wgPageName"));
		var targetJSON = "https://dev.libertygame.work/index.php/RPG_in_City/game.json?action=raw";
		fetch(targetJSON).then(function(result){return result.json(); }).then(function (response) {
		  const editor = new JSONEditor(jsonEditorContainer, {
		  	mode: 'tree',
		    schema: schema,
		    theme: 'tailwind',
		    iconlib: 'openiconic',
		    keep_oneof_values: false,
		    disable_edit_json: true
		  }, response);
		
		  editor.on('change', function () {
		    editorvalue.value = JSON.stringify(editor.getValue(), null, 2);
		  });
		  
	  }).catch('JSON 에디터 로딩 후 JSON 타겟 가져오기 실패');
	});
	document.getElementById("value").addEventListener('change', (ev) => {
		ev.preventDefaults();
	});
	
};

$(addJSONEditor);