Skip to content

Commit

Permalink
Merge pull request #12 from dlh01/0.3
Browse files Browse the repository at this point in the history
Version 0.3
  • Loading branch information
dlh01 authored Jan 3, 2017
2 parents c6cd9f0 + 51a65f4 commit bc31089
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 638 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Fieldmanager Beta: Customize #
**Contributors:** [dlh](https://profiles.wordpress.org/dlh), [alleyinteractive](https://profiles.wordpress.org/alleyinteractive)
**Contributors:** [dlh](https://profiles.wordpress.org/dlh), [jamesburke](https://profiles.wordpress.org/jamesburke), [alleyinteractive](https://profiles.wordpress.org/alleyinteractive)
**Requires at least:** 4.4
**Tested up to:** 4.7
**Stable tag:** 0.2.1
**Stable tag:** 0.3.0
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

A Fieldmanager Beta plugin for the Customize Context.

## Description ##

This is the proposed Customize context for Fieldmanager. You can install the plugin alongside a stable Fieldmanager release to help test and refine the context.
This is a proposed Customize context for Fieldmanager. You can install the plugin alongside a stable Fieldmanager release to help test and refine the context.

The official Pull Request for the Customize context, plus tests, is [on GitHub](https://github.com/alleyinteractive/wordpress-fieldmanager/pull/399).
The official Pull Request for this context, plus tests, is [on GitHub](https://github.com/alleyinteractive/wordpress-fieldmanager/pull/399).

## Installation ##

Expand Down Expand Up @@ -41,6 +41,12 @@ For more code examples, browse `php/demos/class-fieldmanager-beta-customize-demo

## Changelog ##

### 0.3.0 ###
* Changed: `Fieldmanager_RichTextArea` is now supported natively; using `Fieldmanager_Beta_Customize_RichTextArea` is no longer required.
* Changed: Move remaining scripts that overrode Fieldmanager core assets into separate files.
* Fixed: Fix invisible TinyMCE popups.
* Deprecated: `Fieldmanager_Beta_Customize_RichTextArea`, per above.

### 0.2.1 ###
* Fix JavaScript errors.

Expand All @@ -52,8 +58,3 @@ For more code examples, browse `php/demos/class-fieldmanager-beta-customize-demo

### 0.1.0 ###
* Initial release.

## Fieldmanager-specific quirks ##

* RichTextAreas: These are supported via the `Fieldmanager_Beta_Customize_RichTextArea` class included with this plugin. Use a `Fieldmanager_Beta_Customize_RichTextArea` in place of `Fieldmanager_RichTextArea` when you want to use TinyMCE in the Customizer.
* Scripts: Some Fieldmanager JavaScript files require changes for the Customize context. This plugin includes the updated versions of those files and filters Fieldmanager to return them.
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@
/* Nudge for the Customizer. */
max-width: 80%;
}

/* Fix invisible TinyMCE popups. Props Customize Posts: https://github.com/xwp/wp-customize-posts. */

.wp-customizer #wp-link-wrap {
z-index: 500105; /* originally 100105, but z-index of .wp-full-overlay is 500000 */
}

.wp-customizer #wp_editbtns,
.wp-customizer #wp_gallerybtns {
z-index: 500020; /* originally 100020, but z-index of .wp-full-overlay is 500000 */

}
.wp-customizer #TB_overlay,
.wp-customizer #TB_window {
z-index: 500050;
}

.wp-customizer .mce-panel,
.wp-customizer .mce-tooltip {
z-index: 500100 !important; /* originally 100100, but z-index of .wp-full-overlay is 500000 */
}
64 changes: 38 additions & 26 deletions fieldmanager-beta-customize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Plugin Name: Fieldmanager Beta: Customize
* Plugin URI: https://www.github.com/dlh01/fieldmanager-beta-customize-context
* Description: Add Fieldmanager fields to the Customizer.
* Author: David Herrera, Alley Interactive
* Author: David Herrera, James Burke, Alley Interactive
* Author URI: https://www.alleyinteractive.com
* Text Domain: fieldmanager-beta-customizer
* Domain Path: /languages
* Version: 0.2.1
* Version: 0.3.0
*
* @package Fieldmanager_Beta_Customize
*/
Expand All @@ -25,7 +25,7 @@
/**
* Plugin version.
*/
define( 'FM_BETA_CUSTOMIZE_VERSION', '0.2.1' );
define( 'FM_BETA_CUSTOMIZE_VERSION', '0.3.0' );

/**
* Calculate a Fieldmanager context for the Customizer.
Expand Down Expand Up @@ -58,29 +58,6 @@
require_once( FM_BETA_CUSTOMIZE_PATH . 'php/field/class-fieldmanager-beta-customize-richtextarea.php' );
}, 0 );

/**
* Override the path to some Fieldmanager scripts to use updated versions from this plugin.
*
* @param array Arrays of script arguments. @see Fieldmanager_Util_Assets::add_script().
*/
add_filter( 'fm_enqueue_scripts', function ( $scripts ) {
return array_map(
function ( $script ) {
switch ( $script['handle'] ) {
case 'fm_colorpicker' :
case 'fieldmanager_script' :
case 'fm_richtext' :
$script['ver'] = FM_BETA_CUSTOMIZE_VERSION;
$script['path'] = str_replace( fieldmanager_get_baseurl(), FM_BETA_CUSTOMIZE_URL, $script['path'] );
break;
}

return $script;
},
$scripts
);
} );

/**
* Enqueue assets managed by Fieldmanager_Util_Assets in the Customizer.
*/
Expand All @@ -95,6 +72,41 @@ function ( $script ) {
}
} );

/**
* Print Customizer control scripts for editors in the footer.
*
* This action must fire after settings are exported in WP_Customize_Manager::customize_pane_settings().
*
* @since 0.3.0
*/
add_action( 'customize_controls_print_footer_scripts', function () {
if ( wp_script_is( 'fm_richtext', 'enqueued' ) && class_exists( '_WP_Editors' ) ) {
if ( false === has_action( 'customize_controls_print_footer_scripts', array( '_WP_Editors', 'editor_js' ) ) ) {
// Print the necessary JS for an RTE, unless we can't or suspect it's already there.
_WP_Editors::editor_js();
_WP_Editors::enqueue_scripts();
}
}
}, 1001 );

/**
* Use a "teeny" editor by default in the Customizer to conserve space.
*
* @since 0.3.0
*
* @param array $settings Array of editor arguments.
* @param string $editor_id ID for the current editor instance.
*/
add_filter( 'wp_editor_settings', function ( $settings, $editor_id ) {
if ( ( substr( $editor_id, 0, 3 ) === 'fm-' ) && is_customize_preview() ) {
if ( ! isset( $settings['teeny'] ) ) {
$settings['teeny'] = true;
}
}

return $settings;
}, 10, 2 );

/**
* Add a field to the Customizer.
*
Expand Down
20 changes: 0 additions & 20 deletions js/beta-overrides.js

This file was deleted.

104 changes: 104 additions & 0 deletions js/fieldmanager-beta-customize-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* Integrate this beta plugin with core Fieldmanager scripts.
*/
(function( $ ) {
// Enable Autocomplete when focusing on an Autocomplete input.
if ( fm.autocomplete ) {
$( document ).on( 'focus',
'input[class*="fm-autocomplete"]:not(.fm-autocomplete-enabled)',
fm.autocomplete.enable_autocomplete
);
}

$( document ).on( 'fm_beta_customize_control_section_expanded', function () {
// Initialize Datepickers.
if ( fm.datepicker ) {
fm.datepicker.add_datepicker();
}

// Initialize display-ifs.
if ( fm.init_display_if ) {
$( '.display-if' ).each( fm.init_display_if );
}

// Initialize Colorpickers and respond to changes.
if ( fm.colorpicker ) {
fm.colorpicker.init();

$( '.fm-colorpicker-popup' ).each(function () {
var $this = $( this );

if ( $this.wpColorPicker( 'instance' ) && ! $this.data( 'fm-beta-customize' ) ) {
$this.data( 'fm-beta-customize', true );

$this.wpColorPicker( 'instance' ).option( 'change', function ( event, ui ) {
// Make sure the input's value attribute also changes.
$this.attr( 'value', ui.color.toString() );
fm.beta.customize.setControlsContainingElement( this );
});

$this.wpColorPicker( 'instance' ).option( 'clear', function () {
// Make sure the input's value attribute also changes.
$this.attr( 'value', '' );
fm.beta.customize.setControlsContainingElement( this );
});
}
});
}

// Initialize RichTextAreas and respond to changes.
if ( fm.richtextarea ) {
fm.richtextarea.add_rte_to_visible_textareas();

tinymce.editors.forEach(function ( ed ) {
var $fm_richtext = $( document.getElementById( ed.id ) );

if ( $fm_richtext.hasClass( 'fm-richtext' ) && ! $fm_richtext.data( 'fm-beta-customize' ) ) {
$fm_richtext.data( 'fm-beta-customize', true );

// SetContent handles adding images from the media modal and pasting.
ed.on( 'keyup AddUndo SetContent', function () {
ed.save();
fm.beta.customize.setControlsContainingElement( document.getElementById( ed.id ) );
});
}
});
}

// Initialize sortables via existing event.
$( document ).trigger( 'fm_activate_tab' );

// Initialize label macros with a copy of init_label_macros(), which is
// suboptimal but more optimal than copying all of fieldmanager.js.
(function() {
$( '.fm-label-with-macro' ).each( function( label ) {
$( this ).data( 'label-original', $( this ).html() );
var src = $( this ).parents( '.fm-group' ).first().find( $( this ).data( 'label-token' ) );
if ( src.length > 0 ) {
var $src = $( src[0] );
if ( typeof $src.val === 'function' ) {
var $label = $( this );
var title_macro = function() {
var token = '';
if ( $src.prop( 'tagName' ) == 'SELECT' ) {
var $option = $src.find( 'option:selected' );
if ( $option.val() ) {
token = $option.text();
}
} else {
token = $src.val();
}
if ( token.length > 0 ) {
$label.html( $label.data( 'label-format' ).replace( '%s', token ) );
} else {
$label.html( $label.data( 'label-original' ) );
}
};
$src.on( 'change keyup', title_macro );
title_macro();
}
}
} );
})();
});
})( jQuery );
Loading

0 comments on commit bc31089

Please sign in to comment.