-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from GravityKit/feature/189-add-a-unique-key-…
…when-embedding-shortcode Add a unique key when embedding shortcode
- Loading branch information
Showing
11 changed files
with
499 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,103 @@ | ||
var gfexcel_sortable; | ||
|
||
(function ($) { | ||
var updateLists = function ($elements) { | ||
$elements.each(function (i, el) { | ||
var $input = $(el).prevAll('input[type=hidden]'); | ||
$input.val($(el).sortable('toArray', {attribute: 'data-value'}).join(',')); | ||
}) | ||
}; | ||
|
||
gfexcel_sortable = function (elements, connector_class) { | ||
var $elements = $(elements); | ||
var labels_i10n = typeof gravityexport_lite_strings !== 'undefined' | ||
? gravityexport_lite_strings | ||
: {'enable': 'Enable all', 'disable': 'Disable all'}; // Fallback to English | ||
|
||
$elements.each(function () { | ||
var $list = $(this); | ||
var send_to = '#' + $list.data('send-to'); | ||
var label = send_to.indexOf('enabled') > 0 ? labels_i10n.enable : labels_i10n.disable; | ||
var $move_all_button = $('<button type="button">' + label + '</button>'); | ||
|
||
$move_all_button | ||
// Add css via JS to hit add-ons. | ||
.css({ | ||
background: 'none', | ||
border: 0, | ||
float: 'right', | ||
marginTop: '-30px', | ||
color: '#3e7da6', | ||
cursor: 'pointer' | ||
}) | ||
// Move all items to the `send-to` list when clicked. | ||
.on('click', function () { | ||
$list.find('li').appendTo($(send_to)); | ||
$elements.sortable('refresh'); | ||
updateLists($elements); | ||
}); | ||
|
||
// Add the button before the list. | ||
$(this).before($move_all_button); | ||
}); | ||
|
||
$elements.sortable({ | ||
connectWith: '.' + connector_class, | ||
update: function () { | ||
updateLists($elements); | ||
} | ||
}).disableSelection(); | ||
|
||
$elements | ||
.on('click', '.move', function () { | ||
var element = $(this).closest('li'); | ||
var send_to = '#' + element.closest('ul').data('send-to'); | ||
element.appendTo($(send_to)); | ||
setTimeout(function () { | ||
element.addClass('light-up'); | ||
setTimeout(function () { | ||
element.removeClass('light-up'); | ||
}, 200); | ||
}, 10); | ||
$elements.sortable('refresh'); | ||
updateLists($elements); | ||
}); | ||
}; | ||
|
||
$(document).ready(function () { | ||
$("#start_date, #end_date").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true}); | ||
}); | ||
})(jQuery); | ||
( function ( $ ) { | ||
var updateLists = function ( $elements ) { | ||
$elements.each( function ( i, el ) { | ||
var $input = $( el ).prevAll( 'input[type=hidden]' ); | ||
$input.val( $( el ).sortable( 'toArray', { attribute: 'data-value' } ).join( ',' ) ); | ||
} ) | ||
}; | ||
|
||
gfexcel_sortable = function ( elements, connector_class ) { | ||
var $elements = $( elements ); | ||
var labels_i10n = typeof gravityexport_lite_strings !== 'undefined' | ||
? gravityexport_lite_strings | ||
: { 'enable': 'Enable all', 'disable': 'Disable all' }; // Fallback to English | ||
|
||
$elements.each( function () { | ||
var $list = $( this ); | ||
var send_to = '#' + $list.data( 'send-to' ); | ||
var label = send_to.indexOf( 'enabled' ) > 0 ? labels_i10n.enable : labels_i10n.disable; | ||
var $move_all_button = $( '<button type="button">' + label + '</button>' ); | ||
|
||
$move_all_button | ||
// Add css via JS to hit add-ons. | ||
.css( { | ||
background: 'none', | ||
border: 0, | ||
float: 'right', | ||
marginTop: '-30px', | ||
color: '#3e7da6', | ||
cursor: 'pointer' | ||
} ) | ||
// Move all items to the `send-to` list when clicked. | ||
.on( 'click', function () { | ||
$list.find( 'li' ).appendTo( $( send_to ) ); | ||
$elements.sortable( 'refresh' ); | ||
updateLists( $elements ); | ||
} ); | ||
|
||
// Add the button before the list. | ||
$( this ).before( $move_all_button ); | ||
} ); | ||
|
||
$elements.sortable( { | ||
connectWith: '.' + connector_class, | ||
update: function () { | ||
updateLists( $elements ); | ||
} | ||
} ).disableSelection(); | ||
|
||
$elements | ||
.on( 'click', '.move', function () { | ||
var element = $( this ).closest( 'li' ); | ||
var send_to = '#' + element.closest( 'ul' ).data( 'send-to' ); | ||
element.appendTo( $( send_to ) ); | ||
setTimeout( function () { | ||
element.addClass( 'light-up' ); | ||
setTimeout( function () { | ||
element.removeClass( 'light-up' ); | ||
}, 200 ); | ||
}, 10 ); | ||
$elements.sortable( 'refresh' ); | ||
updateLists( $elements ); | ||
} ); | ||
}; | ||
|
||
$( document ).ready( function () { | ||
const $embedShortcodeEl = $( '#embed_code' ); | ||
const secret = $embedShortcodeEl.data( 'secret' ); | ||
|
||
$( '#start_date, #end_date' ).datepicker( { dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true } ); | ||
|
||
$( '#file_extension' ).on( 'change', function () { | ||
const shortcode = $embedShortcodeEl.val(); | ||
const has_type = shortcode.match( / type=/ ); | ||
const regex = has_type ? / type="[^"]*"/ : /]$/; | ||
|
||
let type = ` type="${ $( this ).val() }"`; | ||
|
||
if ( !has_type ) { | ||
type += ']'; | ||
} | ||
|
||
$embedShortcodeEl.val( shortcode.replace( regex, type ) ); | ||
} ); | ||
|
||
$( '#has_embed_secret' ).on( 'change', function () { | ||
let embedShortcode = $embedShortcodeEl.val(); | ||
|
||
if ( !embedShortcode ) { | ||
return; | ||
} | ||
|
||
if ( $( this ).is( ':checked' ) ) { | ||
embedShortcode = embedShortcode.replace( /]$/, ` secret="${ secret }"]` ); | ||
} else { | ||
embedShortcode = embedShortcode.replace( / secret="[^"]+"/, '' ); | ||
} | ||
|
||
$embedShortcodeEl.val( embedShortcode ); | ||
} ); | ||
} ); | ||
} )( jQuery ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace GFExcel\GravityForms\Field; | ||
|
||
use Gravity_Forms\Gravity_Forms\Settings\Fields\HTML; | ||
use GFExcel\Shortcode\DownloadUrl; | ||
|
||
/** | ||
* A field that contains the embed shortcode for this feed, with a copy to clipboard button. | ||
* @since $ver$ | ||
*/ | ||
final class CopyShortcode extends HTML { | ||
/** | ||
* @inheritdoc | ||
* @since $ver$ | ||
*/ | ||
public $type = 'copy_shortcode'; | ||
|
||
/** | ||
* @since $ver$ | ||
* @var null|string | ||
*/ | ||
protected $embed_type; | ||
|
||
/** | ||
* @inheritdoc | ||
* @since $ver$ | ||
*/ | ||
public function scripts(): array { | ||
$script = <<<JS | ||
(function($) { | ||
$( document ).ready(function() { | ||
addClipboard('%s','%s'); | ||
}); | ||
})(jQuery); | ||
JS; | ||
|
||
return [ | ||
[ | ||
'handle' => 'gk-gravityexport-clipboard-js', | ||
'callback' => function () use ( $script ) { | ||
wp_add_inline_script( | ||
'gk-gravityexport-clipboard-js', | ||
sprintf( | ||
$script, | ||
esc_attr( '#copy-embed-code' ), | ||
esc_attr__( 'The shortcode has been copied to your clipboard.', 'gk-gravityexport-lite' ) | ||
) | ||
); | ||
}, | ||
'deps' => [ 'jquery', 'wp-a11y', 'wp-i18n', 'clipboard' ], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @since $ver$ | ||
*/ | ||
public function markup(): string { | ||
$form_id = (int) rgget( 'id' ); | ||
$shortcode = esc_attr( DownloadUrl::generate_embed_short_code( $form_id, $this->embed_type ) ); | ||
$secret = DownloadUrl::get_secret( $form_id ); | ||
$copy_shortcode = esc_html__( 'Copy Shortcode', 'gk-gravityexport-lite' ); | ||
|
||
return <<<HTML | ||
<div class="copy-short-code copy-to-clipboard-container"> | ||
<div class="input"><input type="text" readonly value="{$shortcode}" id="embed_code" data-secret="{$secret}"></div> | ||
<div class="success hidden" aria-hidden="true">Copied!</div> | ||
<button id="copy-embed-code" type="button" class="button" data-clipboard-target="[id=embed_code]"> | ||
<span class="dashicons dashicons-clipboard"></span> {$copy_shortcode} | ||
</button> | ||
</div> | ||
HTML; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters