Skip to content

Commit

Permalink
added ability to include tooltips on section blocks. fixes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
norcross committed May 27, 2016
1 parent 2dd2d34 commit 3de3e18
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 66 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### Version 2.0.2 - 2016/05/27
* added ability to include tooltips on section blocks
* moved `gf_tooltips_allowed_fields` filter from `admin.php` file to `helper.php` file to allow checks on front end
* minor cleanup

#### Version 2.0.1 - 2016/01/26
* added GitHub Updater support
Expand Down
4 changes: 2 additions & 2 deletions gravity-tooltips.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Add custom tooltips in Gravity Forms.
* Author: Andrew Norcross
* Author URI: http://andrewnorcross.com/
* Version: 2.0.1
* Version: 2.0.2
* Text Domain: gravity-tooltips
* Requires WP: 4.0
* Domain Path: languages
Expand Down Expand Up @@ -43,7 +43,7 @@

// Define our version if we haven't already.
if( ! defined( 'GFT_VER' ) ) {
define( 'GFT_VER', '2.0.1' );
define( 'GFT_VER', '2.0.2' );
}

/**
Expand Down
54 changes: 1 addition & 53 deletions lib/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function scripts_styles( $hook ) {
wp_enqueue_script( 'gftips-admin', plugins_url( '/js/gftips.admin.js', __FILE__ ), array( 'jquery' ), GFT_VER, true );
wp_localize_script( 'gftips-admin', 'gftipsAdmin',
array(
'fldTypes' => self::show_field_item_types()
'fldTypes' => GF_Tooltips_Helper::show_field_item_types()
)
);
}
Expand Down Expand Up @@ -346,58 +346,6 @@ public static function settings_page() {
echo '</div>';
}

/**
* Set up all the possible field types.
*
* @return array $fields All the field types.
*/
public static function show_field_item_types() {

// Set the array of field types.
$fields = array(
'text',
'creditcard',
'website',
'phone',
'number',
'date',
'time',
'textarea',
'select',
'multiselect',
'checkbox',
'radio',
'name',
'address',
'fileupload',
'email',
'post_title',
'post_content',
'post_excerpt',
'post_tags',
'post_category',
'post_image',
'captcha',
'product',
'singleproduct',
'calculation',
'price',
'hiddenproduct',
'list',
'shipping',
'singleshipping',
'option',
'quantity',
'donation',
'total',
'post_custom_field',
'password'
);

// Return the types, filtered.
return apply_filters( 'gf_tooltips_allowed_fields', $fields );
}

/**
* Get the dropdown for the design.
*
Expand Down
42 changes: 31 additions & 11 deletions lib/front.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ public function set_tooltip_display( $content, $field, $value, $lead_id, $form_i
return $content;
}

// Fetch our field types.
$ftypes = GF_Tooltips_Helper::show_field_item_types();

// Bail if this object has no type, or isn't one we allow.
if ( empty( $field->type ) || ! in_array( $field->type, $ftypes ) ) {
return $content;
}

// Bail if no tooltip actually exists.
if ( empty( $field['customTooltip'] ) ) {
if ( empty( $field->customTooltip ) ) {
return $content;
}

Expand All @@ -108,12 +116,12 @@ public function set_tooltip_display( $content, $field, $value, $lead_id, $form_i
}

// Filter the text.
if ( false === $text = apply_filters( 'gf_tooltips_text', $field['customTooltip'], $field, $form_id ) ) {
if ( false === $text = apply_filters( 'gf_tooltips_text', $field->customTooltip, $field, $form_id ) ) {
return $content;
}

// Render and return.
return self::render_tooltip_markup( $field['customTooltip'], $type, $content, $field, $form_id );
return self::render_tooltip_markup( $field->customTooltip, $type, $content, $field, $form_id );
}

/**
Expand All @@ -135,39 +143,51 @@ public static function render_tooltip_markup( $text = '', $type = '', $render =
$class = self::get_tooltip_class( $design, $target, $type );

// Build out label version.
if ( $type == 'label' ) {
if ( 'label' === $type ) {

// Determine which label class to filter based on field type.
$lclass = 'section' === $field->type ? 'gsection_title' : 'gfield_label';

// Determine what to attach to, since sections get handled differently due to markup differences.
$attach = 'section' === $field->type ? '<h2' : '<label';

// First add the class.
$render = GF_Tooltips_Helper::str_replace_limit( 'gfield_label', 'gfield_label ' . $class, $render );
$render = GF_Tooltips_Helper::str_replace_limit( $lclass, $lclass . ' ' . $class, $render );

// Now add the tooltip.
$render = GF_Tooltips_Helper::str_replace_limit( '<label', '<label data-hint="' . esc_attr( $text ) . '"', $render );
$render = GF_Tooltips_Helper::str_replace_limit( $attach, $attach . ' data-hint="' . esc_attr( $text ) . '"', $render );
}

// Build out icon version.
if ( $type == 'icon' ) {
if ( 'icon' === $type ) {

// Get my icon.
$icon = self::get_tooltip_icon();

// Build the markup.
$setup = '<span class="gf-icon ' . $class . '" data-hint="' . esc_attr( $text ) . '">' . $icon . '</span>';

// Render it.
$render = GF_Tooltips_Helper::str_replace_limit( '</label>', $setup . '</label>', $render );
// Determine what to attach to, since sections get handled differently due to markup differences.
$attach = 'section' === $field->type ? '</h2>' : '</label>';

// And render it.
$render = GF_Tooltips_Helper::str_replace_limit( $attach, $setup . $attach, $render );
}

// Build out single version.
if ( $type == 'single' ) {
if ( 'single' === $type ) {

// Get my icon.
$icon = self::get_tooltip_icon();

// Build the markup.
$setup = '<span class="gf-icon ' . $class . '" data-hint="' . esc_attr( $text ) . '">' . $icon . '</span>';

// Determine what to attach to, since sections get handled differently due to markup differences.
$attach = 'section' === $field->type ? '</h2>' : '</div>';

// Render it.
$render = GF_Tooltips_Helper::str_replace_limit( '</div>', '</div>' . $setup, $render );
$render = GF_Tooltips_Helper::str_replace_limit( $attach, $attach . $setup, $render );
}

// Return field content with new tooltip.
Expand Down
53 changes: 53 additions & 0 deletions lib/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,59 @@ public static function str_replace_limit( $search = '', $replace = '', $string =
return $string;
}

/**
* Set up all the possible field types.
*
* @return array $fields All the field types.
*/
public static function show_field_item_types() {

// Set the array of field types.
$fields = array(
'text',
'creditcard',
'website',
'phone',
'number',
'date',
'time',
'textarea',
'select',
'multiselect',
'checkbox',
'radio',
'name',
'address',
'fileupload',
'email',
'post_title',
'post_content',
'post_excerpt',
'post_tags',
'post_category',
'post_image',
'captcha',
'product',
'singleproduct',
'calculation',
'price',
'hiddenproduct',
'list',
'shipping',
'singleshipping',
'option',
'quantity',
'donation',
'total',
'post_custom_field',
'password',
'section'
);

// Return the types, filtered.
return apply_filters( 'gf_tooltips_allowed_fields', $fields );
}

// End our class.
}

Expand Down

0 comments on commit 3de3e18

Please sign in to comment.