Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
tigger confirmations, examples for confirmation and copy-to-clipboard
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Apr 21, 2017
1 parent 4ab0597 commit 706276c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 4 deletions.
10 changes: 10 additions & 0 deletions blueprints/fields/openerclipboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# opener example for opening file as popup window
type: opener
label: Example 9
command: '{page.url}/copy:yes'
help: '{page.url}/copy:yes'
text: 'Copy URL of Frontend Page to Clipboard'
textprogress: 'Copy URL of Frontend Page to Clipboard'
textsuccess: 'Copied'
texterror: 'No Browser Support'
width: 1/2
11 changes: 11 additions & 0 deletions blueprints/fields/openerconfirmation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# opener example for opening file as popup window
type: opener
label: Example 10
command: '/openerexample-route/success/{page.diruri.encoded}/{page.secret}'
help: '/openerexample-route/success/{page.diruri.encoded}/{page.secret}'
text: 'Like #6 but with Confirmation'
textprogress: 'baking...'
textsuccess: 'YML :)'
texterror: 'YML :('
width: 1/2
confirm: 'Hungry?'
2 changes: 2 additions & 0 deletions blueprints/openerexample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ fields:
example6: openersuccess
example7: openererror
example8: openercontroller
example9: openerclipboard
example10: openerconfirmation

placeholders-line:
type: line
Expand Down
7 changes: 7 additions & 0 deletions fields/opener/assets/js/script.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Opener = ($, $field) ->
progress: this.$text.attr 'data-textprogress'
success : this.$text.attr 'data-textsuccess'
error : this.$text.attr 'data-texterror'
confirm : this.$text.attr 'data-textconfirm'

this.parseResult = (result) ->
if result[this.jsoncode] is 200
Expand Down Expand Up @@ -125,6 +126,12 @@ Opener = ($, $field) ->
this.$field.find('a.opener').click (ev) ->
ev.preventDefault()

confirmed = true
if self.$opener.hasClass 'confirm'
confirmed = confirm(self.l.confirm)

if not confirmed then return

if self.$opener.hasClass 'no-ajax'
window.open self.$button.attr('href')
else if self.$opener.hasClass 'copy-clipboard'
Expand Down
2 changes: 1 addition & 1 deletion fields/opener/assets/js/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fields/opener/opener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OpenerField extends BaseField {
public $textsuccess;
public $texterror;
public $command;
public $confirm;

public function input() {

Expand Down
7 changes: 5 additions & 2 deletions fields/opener/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@
$placeholder = a::merge($placeholder, $fieldValues);
}

if(c::get('debug', false)) {
if(c::get('plugin.opener.debug', false)) {
echo '<style>.opener-debug {border:1px solid #ccc;background-color:#ddd;padding:20px;margin-bottom:20px;} .opener-debug pre{font-family: monospace;word-wrap:break-word;}</style><div class="opener-debug">'.a::show($placeholder, false).'</div>';
}

$confirm = isset($field->confirm) ? boolval($field->confirm) : false;

$href = url(str::template($field->command, $placeholder));
$download = str::contains($href, c::get('plugin.opener.trigger-download', 'download:yes'));

Expand All @@ -150,7 +152,7 @@

<div class="<?php echo $fieldname ?>-wrapper">
<div
class="<?php echo $fieldname ?>-button <?php ecco($popup, 'popup ', '') ?><?php ecco($download, 'download ', '') ?><?php ecco($open, 'no-ajax ', '') ?><?php ecco($copy, 'copy-clipboard ', '') ?><?php ecco($refresh, 'refresh ', '') ?>"
class="<?php echo $fieldname ?>-button <?php ecco($popup, 'popup ', '') ?><?php ecco($download, 'download ', '') ?><?php ecco($open, 'no-ajax ', '') ?><?php ecco($copy, 'copy-clipboard ', '') ?><?php ecco($refresh, 'refresh ', '') ?><?php ecco($confirm,'confirm ','') ?>"
data-delay="<?php echo $delay; ?>"
data-jsoncode="<?php echo $code; ?>"
data-jsonmessage="<?php echo $message; ?>"
Expand All @@ -169,6 +171,7 @@ class="btn btn-rounded <?php echo $field->type(); ?>"
data-textsuccess="<?php echo $field->textsuccess; ?>"
data-textopening="<?php echo $field->textopening; ?>"
data-textprogress="<?php echo $field->textprogress; ?>"
data-textconfirm="<?php echo $field->confirm; ?>"
data-textdefault="<?php echo $field->text; ?>"><?php echo $field->text; ?></span></a>
<?php if($download): ?><a id="<?php echo $field->name(); ?>-download" href="" download="" class="<?php echo $fieldname ?>-download" target="_blank">Download</a><?php endif; ?>
<?php if($copy):?>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kirby-opener",
"description": "Kirby Opener is a Kirby CMS Panel Field button that allows you to use placeholders to create dynamic urls which are called with and without ajax response or start downloads.",
"version": "0.8.2",
"version": "0.9.0",
"author": "Bruno Meilick",
"type": "kirby-plugin",
"license": "Commercial"
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Kirby Opener is a Kirby CMS Panel Field button that allows you to use placeholde
- trigger downloading of files
- trigger clipboard copy of url
- trigger refresh of page on success
- trigger browser confirmation dialog
- easily extendable *placeholders*
- configural parsing of *json response*

Expand Down

0 comments on commit 706276c

Please sign in to comment.