Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing click to double click. fix typos. cleanup #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions acf-flexible-content-modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
* Plugin Name: ACF Flexible Content Modal
* Description: Make ACF Flexible Content editing the content of each layout using a Modal window.
* Plugin URI: http://wordpress.org/plugins/acf-flexible-content-modal/
* Version: 1.2.3
* Version: 1.2.4
* Author: Edir Pedro
* Author URI: http://edirpedro.com.br
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: acf-fc-modal
*/


// File Security Check
defined('ABSPATH') or die("No script kiddies please!");
defined('ABSPATH') or die('No script kiddies please!');


class ACFFCM {

// Unique name of the module
static private $id = 'acf-fc-modal';

// Path
static private $path = '';

Expand All @@ -30,7 +30,7 @@ class ACFFCM {
*/
static public function init() {
global $acf;

// Path
if($acf) {
if(version_compare($acf->version, '5.7.0', '<'))
Expand All @@ -42,51 +42,51 @@ static public function init() {
add_action('init', array(__CLASS__, 'theme_script'));
add_action('admin_init', array(__CLASS__, 'admin_css'), 1, 999);
add_action('admin_init', array(__CLASS__, 'admin_script'),1, 999);

}

/*
* Process plugin activation
*/
static public function activate() {

}

/*
* Process plugin deactivation
*/
static public function deactivate() {

}

/*
* Register Admin Stylesheets
*/
static public function admin_css() {
wp_enqueue_style('acf-fc-modal', plugins_url(self::$path . '/style.css', __FILE__), array('acf-pro-input'));
}

/*
* Register Admin Scripts
*/
static public function admin_script() {
wp_enqueue_script('acf-fc-modal', plugins_url(self::$path . '/script.js', __FILE__), array('acf-pro-input'));
}

/*
* Register Theme Stylesheets
*/
static public function theme_css() {

}

/*
* Register Theme Scripts
*/
static public function theme_script() {

}

}

// Activating
Expand Down
155 changes: 77 additions & 78 deletions acf/5.6/script.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,96 @@

jQuery(document).ready(function() {
try {
// Add Elements button
var acf_fc_render = acf.fields.flexible_content.render;
acf.fields.flexible_content.render = function() {
acf_fc_modal_init();
acf_fc_modal_handle_validation();
return acf_fc_render.apply(this, arguments);
}
// ACF FC Modal
acf_fc_modal_init();
} catch(e) {}

try {

// Add Elements button
var acf_fc_render = acf.fields.flexible_content.render;
acf.fields.flexible_content.render = function() {
acf_fc_modal_init();
acf_fc_modal_handle_validation();
return acf_fc_render.apply(this, arguments);
}

// ACF FC Modal
acf_fc_modal_init();

} catch (e) {}

});

// Init Modal
function acf_fc_modal_init() {
jQuery('.acf-flexible-content .layout:not(.acf-clone)').each(function() {
var layout = jQuery(this);
// Ignoring if it is a nested FC
if(layout.parents('.acf-fields').length > 1)
return true;
else
layout.addClass('fc-modal');
// Remove Toggle button and click event
layout.find('> .acf-fc-layout-handle').off('click');
layout.find('> .acf-fc-layout-controlls > li:last-child').remove(); // ACF 5.4
layout.find('> .acf-fc-layout-controlls > a:last-child').remove(); // ACF 5.5
// Edit button
var controls = layout.find('> .acf-fc-layout-controlls');
if(controls.is('ul'))
controls.append('<li><a class="acf-icon -pencil small light" href="#" data-event="edit-layout" title="Edit layout"></a></li>');
else
controls.append('<a class="acf-icon -pencil small light" href="#" data-event="edit-layout" title="Edit layout"></a>');
layout.find('> .acf-fc-layout-controlls a.-pencil').on('click', acf_fc_modal_open);
// Add modal elements
if(layout.find('> .acf-fc-modal-title').length == 0) {
layout.prepend('<div class="acf-fc-modal-title"></div>');
layout.find('> .acf-fields, > .acf-table').wrapAll('<div class="acf-fc-modal-content"></div>');
}
});

jQuery('.acf-flexible-content .layout:not(.acf-clone)').each(function() {
var layout = jQuery(this);

// Ignoring if it is a nested FC
if (layout.parents('.acf-fields').length > 1)
return true;
else
layout.addClass('fc-modal');

// Remove Toggle button and click event
layout.find('> .acf-fc-layout-handle').off('click');
layout.find('> .acf-fc-layout-controls > li:last-child').remove(); // ACF 5.4
layout.find('> .acf-fc-layout-controls > a:last-child').remove(); // ACF 5.5

// Edit button
var controls = layout.find('> .acf-fc-layout-controls');
if (controls.is('ul'))
controls.append('<li><a class="acf-icon -pencil small light" href="#" data-event="edit-layout" title="Edit layout"></a></li>');
else
controls.append('<a class="acf-icon -pencil small light" href="#" data-event="edit-layout" title="Edit layout"></a>');
layout.find('> .acf-fc-layout-controls a.-pencil').on('click', acf_fc_modal_open);

// Add modal elements
if (layout.find('> .acf-fc-modal-title').length == 0) {
layout.prepend('<div class="acf-fc-modal-title"></div>');
layout.find('> .acf-fields, > .acf-table').wrapAll('<div class="acf-fc-modal-content"></div>');
}

});

}

// Open Modal
function acf_fc_modal_open() {
var layout = jQuery(this).parents('.layout');
if(!layout.hasClass('-modal')) {
layout.removeClass('-collapsed');
var caption = layout.find('> .acf-fc-layout-handle').html();
layout.find('.acf-fc-modal-title').html(caption + '<a class="acf-icon -cancel" href="javascript:acf_fc_modal_remove()">');
layout.addClass('-modal');
jQuery("body").append("<div id='acf-flexible-content-modal-overlay'></div>");
jQuery("#acf-flexible-content-modal-overlay").click(acf_fc_modal_remove);
jQuery('body').addClass('acf-modal-open');
}
var layout = jQuery(this).parents('.layout');
if (!layout.hasClass('-modal')) {
layout.removeClass('-collapsed');
var caption = layout.find('> .acf-fc-layout-handle').html();
layout.find('.acf-fc-modal-title').html(caption + '<a class="acf-icon -cancel" href="javascript:acf_fc_modal_remove()">');
layout.addClass('-modal');
jQuery('body').append('<div id="acf-flexible-content-modal-overlay"></div>');
jQuery('#acf-flexible-content-modal-overlay').click(acf_fc_modal_remove);
jQuery('body').addClass('acf-modal-open');
}
}

// Close Modal
function acf_fc_modal_remove() {
jQuery('body').removeClass('acf-modal-open');
jQuery('.acf-flexible-content .layout.-modal > .acf-fc-layout-handle').click(); // To reload layout title
jQuery('.acf-flexible-content .layout').removeClass('-modal');
jQuery("#acf-flexible-content-modal-overlay").remove();
jQuery('body').removeClass('acf-modal-open');
jQuery('.acf-flexible-content .layout.-modal > .acf-fc-layout-handle').click(); // To reload layout title
jQuery('.acf-flexible-content .layout').removeClass('-modal');
jQuery('#acf-flexible-content-modal-overlay').remove();
}

// Indicate after validation failures
function acf_fc_modal_handle_validation() {
acf.add_action('validation_begin', function() {
jQuery('.acf-flexible-content .layout').removeClass('layout-error-messages');
});
acf.add_action('add_field_error', function($field) {
$field.parents('.layout:not(.acf-clone)').addClass('layout-error-messages');
});
acf.add_action('remove_field_error', function($field) {
$field.parents('.layout:not(.acf-clone)').each(function() {
var layout = jQuery(this);
if(layout.find('.acf-error').length == 0)
layout.removeClass('layout-error-messages');
});
});

acf.add_action('validation_begin', function() {
jQuery('.acf-flexible-content .layout').removeClass('layout-error-messages');
});

acf.add_action('add_field_error', function($field) {
$field.parents('.layout:not(.acf-clone)').addClass('layout-error-messages');
});

acf.add_action('remove_field_error', function($field) {
$field.parents('.layout:not(.acf-clone)').each(function() {
var layout = jQuery(this);
if (layout.find('.acf-error').length == 0)
layout.removeClass('layout-error-messages');
});
});

}
Loading