Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from RostiMelk/development
Browse files Browse the repository at this point in the history
Version 2.4.2
  • Loading branch information
RostiMelk authored Apr 12, 2020
2 parents 9c135c3 + b6bfcd4 commit 0eb6e06
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 66 deletions.
Binary file modified icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "ACF Tools",
"version": "2.4.0",
"description": "This is a Chrome extension for Advanced Custom Fields to help with developing sites faster.",
"version": "2.4.2",
"description": "Advanced Custom Fields code made simple!",
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
Expand All @@ -15,7 +15,8 @@
"css": ["styles/style.css"],
"js": [
"lib/jquery-3.4.1.min.js",
"scripts/scripts.js",
"scripts/app.js",
"scripts/misc.js",
"scripts/fields.js"
]
}
Expand Down
80 changes: 29 additions & 51 deletions scripts/scripts.js → scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,44 @@ $(document).ready(function() {
appendFieldNameOnEdit();
});

function copyMessage(message) {
$(".acftools-message").remove();
var dismissBtn = '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>';
$("body").append('<div class="acftools-message notice notice-success is-dismissible"><p>'+message+'</p>'+dismissBtn+'</div>');
$("body").on('click', '.acftools-message .notice-dismiss', function() {
$(".acftools-message").remove();
})
}

function copyStringToClipboard(element) {
var temp = $("<input>");
$("body").append(temp);
temp
.val(
$(element)
.text()
.trim()
)
.select();
document.execCommand("copy");
temp.remove();
}

// Running some functions again when edits are made
$("body").on('click', function() {
setTimeout(function() {
copyFieldName();
openDocs();
}, 100);
})

// Copy the field name feature:
function copyFieldName() {
$("body").on("click", ".li-field-name", function() {
$(".acf-tbody .li-field-name").each(function() {
if(!$(this).children('.copy-field-name').length) {
var str = $(this).text();
$(this).text('');
$(this).append('<a href="#" class="copy-field-name">'+str+'</a>');
}
})
$("body").on("click", ".copy-field-name", function(e) {
e.preventDefault();
copyStringToClipboard(this);
copyMessage('Copied field name to clipboard!');
});
}

function copyCodeToClipboard(fieldCode, subFields) {
var temp = $("<textarea></textarea>")
.val(fieldCode)
.appendTo("body")
.select();
document.execCommand("copy");
temp.remove();

if(subFields.length) {
copyMessage('Copied code with sub fields to clipboard!');
} else {
copyMessage('Copied code to clipboard!');
}
}

// Open ACF Field documentation:
function openDocs() {
$("body").on("click", ".li-field-type", function() {
var type = $(this)
.closest(".acf-field-object")
.attr("data-type");
var url = type.replace("_", "-");
window.open("https://www.advancedcustomfields.com/resources/" + url, "_blank");
});
}

function fieldError() {
alert("Unsupported field, submit an issue on: \nhttps://github.com/RostiMelk/ACF-Tools");
throw new Error("Unsupported field, submit an issue on: \nhttps://github.com/RostiMelk/ACF-Tools");
$(".acf-tbody .li-field-type").each(function() {
if(!$(this).children('.open-field-docs').length) {
var str = $(this).text(),
slug = $(this).closest('.acf-field-object').attr('data-type').replace("_", "-"),
url = "https://www.advancedcustomfields.com/resources/"+slug;
$(this).text('');
$(this).append('<a href="'+url+'" target="_blank" class="open-field-docs">'+str+'</a>');
}
})
}

// Copy ACF meta field code feature:
function appendCopyCodeBtns() {
// Append copy field code button
function appendCopyCodeBtn() {
Expand Down
4 changes: 1 addition & 3 deletions scripts/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ function acf_field(appendCode, fieldName, typeOfField, returnType, seniority, pl
// Copy to clipboard
sessionStorage.removeItem('fieldcode');
sessionStorage.setItem('fieldcode', '\n\t\t' + fieldCode + '\n');



// Copy the code to the clipboard if sub fields are done appending to a repeater or group field
if(!appendCode) {
copyCodeToClipboard(fieldCode, subFields);
}
Expand Down
42 changes: 42 additions & 0 deletions scripts/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function copyMessage(message) {
$(".acftools-message").remove();
var dismissBtn = '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>';
$("body").append('<div class="acftools-message notice notice-success is-dismissible"><p>'+message+'</p>'+dismissBtn+'</div>');
$("body").on('click', '.acftools-message .notice-dismiss', function() {
$(".acftools-message").remove();
})
}

function copyStringToClipboard(element) {
var temp = $("<input>");
$("body").append(temp);
temp
.val(
$(element)
.text()
.trim()
)
.select();
document.execCommand("copy");
temp.remove();
}

function copyCodeToClipboard(fieldCode, subFields) {
var temp = $("<textarea></textarea>")
.val(fieldCode)
.appendTo("body")
.select();
document.execCommand("copy");
temp.remove();

if(subFields.length) {
copyMessage('Copied code with sub fields to clipboard!');
} else {
copyMessage('Copied code to clipboard!');
}
}

function fieldError() {
alert("Unsupported field, submit an issue on: \nhttps://github.com/RostiMelk/ACF-Tools");
throw new Error("Unsupported field, submit an issue on: https://github.com/RostiMelk/ACF-Tools");
}
9 changes: 0 additions & 9 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
}
}

.li-field-name,
.li-field-type {
cursor: pointer;
}
.li-field-name:hover,
.li-field-type:hover {
text-decoration: underline;
}

.row-options {
display: flex;
align-items: center;
Expand Down

0 comments on commit 0eb6e06

Please sign in to comment.