Skip to content

Commit

Permalink
Add copy on click for short code hint.
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Feb 6, 2024
1 parent 2a7f903 commit 086b534
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin-views.css

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions assets/css/scss/admin-views.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1919,14 +1919,33 @@ $dialog-button-padding: 5px;
left: -1px;
font-size: 20px;
line-height: 1;

html[dir=rtl] & {
left: auto;
right: -1px;
}
}

html[dir=rtl] & .code.widefat {
text-align: right;
}

position: relative;

input.code {
cursor: pointer;
}

span.copied {
display: none;
position: absolute;
top: 0;
right: 10px;
background-color: #000;
color: #FFF;
padding: 2px 5px;
border-radius: 5px;
}
}

/** The "Direct Access" section in the Publish metabox */
Expand Down
15 changes: 15 additions & 0 deletions assets/js/admin-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -2802,4 +2802,19 @@
$( document.body ).trigger( 'gravityview/loaded' );
} );

$( document ).on( 'ready', function () {
new ClipboardJS( '.gv-shortcode input.code', {
text: function ( trigger ) {
return $( trigger ).val();
}
} );

$('.gv-shortcode input.code').on('click', function () {
var $el = $(this).closest('.gv-shortcode').find('.copied');
$el.show();
setTimeout(function () {
$el.fadeOut();
}, 1000);
});
} );
}(jQuery));
2 changes: 1 addition & 1 deletion assets/js/admin-views.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions includes/admin/metaboxes/views/shortcode-hint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<div>
<input type="text" readonly="readonly" value="<?php echo esc_attr($shortcode) ?>" class="code widefat" />
<span class="howto"><?php esc_html_e( 'Add this shortcode to a post or page to embed this view.', 'gk-gravityview' ); ?></span>
<span class="copied"><?php esc_html_e( 'Copied!', 'gk-gravityview' ); ?></span>
</div>
</div>
18 changes: 17 additions & 1 deletion includes/class-admin-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,23 @@ static function add_scripts_and_styles( $hook ) {
wp_enqueue_style( 'gravityview_views_datepicker', plugins_url( 'assets/css/admin-datepicker.css', GRAVITYVIEW_FILE ), \GV\Plugin::$version );

// Enqueue scripts
wp_enqueue_script( 'gravityview_views_scripts', plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'jquery-ui-dialog', 'gravityview-jquery-cookie', 'jquery-ui-datepicker', 'underscore' ), \GV\Plugin::$version );
wp_enqueue_script(
'gravityview_views_scripts',
plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ),
[
'jquery-ui-tabs',
'jquery-ui-draggable',
'jquery-ui-droppable',
'jquery-ui-sortable',
'jquery-ui-tooltip',
'jquery-ui-dialog',
'gravityview-jquery-cookie',
'jquery-ui-datepicker',
'underscore',
'clipboard'
],
\GV\Plugin::$version
);

wp_localize_script(
'gravityview_views_scripts',
Expand Down

0 comments on commit 086b534

Please sign in to comment.