Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getTextareas = () => {
- const textareas = {};
- let trs = [...document.querySelectorAll("tr.dynamic-gallery[id^=\"gallery\"]")];
- while (trs[0]) {
- const tr = trs.shift();
- const view = tr.querySelector(".field-view select[name^=\"gallery\"]").value;
- if (view) textareas[view] = tr.querySelector(".field-details textarea");
- }
- return textareas;
- };
- const patchPatches = patch => {
- const textareas = getTextareas();
- for (let view in textareas) {
- const textarea = textareas[view];
- console.debug(textarea.value);
- textarea.value = patch(textarea.value);
- }
- };
- const removeCustomizationId = json => {
- try {
- const obj = JSON.parse(json);
- if (obj.patch) {
- for (let placement in obj.patch) {
- const anyCustomId = Object.keys(obj.patch[placement])[0];
- const customPatch = obj.patch[placement][anyCustomId];
- if (customPatch) {
- obj.patch[placement] = customPatch;
- }
- }
- }
- return JSON.stringify(obj, null, ' ');
- } catch (error) {
- console.error(error.message);
- }
- return json;
- };
- const getIdPatch = idsMap => {
- return json => {
- try {
- const obj = JSON.parse(json);
- if (obj.patch) {
- for (let placement in obj.patch) {
- for (let id in obj.patch[placement]) {
- const customDetails = obj.patch[placement][id];
- if (id in idsMap) {
- obj.patch[placement][idsMap[id]] = customDetails;
- delete obj.patch[placement][id];
- }
- }
- }
- }
- return JSON.stringify(obj, null, ' ');
- } catch (error) {
- console.error(error.message);
- }
- return json;
- };
- };
- const prettify = json => JSON.stringify(JSON.parse(json), null, ' ');
- const idsMap = {
- "16": "24",
- "8": "22",
- "17": "23",
- "25": "26"
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement