Jump to content

HannaCodeDialog


Robin S

Recommended Posts

12 hours ago, Robin S said:

Or here's a hacky solution that involves adding an extra "path" attribute to your Hanna tag...

Just to report that this works well. I also added some css to hide the path attribute in the dialog box, so as not to confuse the user or risk inadvertant amendment.

Super module , super support!

Link to comment
Share on other sites

Following the above discussion, I decided that it made more sense to display the title rather than the path (since it is only for display purposes). I also wanted a solution for attribute types pagelistselectmultiple, not just pagelistselect. In case it is useful to anyone else, my suggested js is:

$(document).ready(function() {
    /* Author: Mark Evens, based on an original script by Robin Sallis */
    /* This version displays the title text rather than the path name */
    /* It also works for pagelistselectmultiple as well as pagelistselect */

    /* Hide the text field  */
    /* id_title is the name of a text attribute in the hanna code*/
    /* change id_title throughout the code below to match your attribute name */
    $('#wrap_id_title').addClass('hide-field');

    // Must use mousedown instead of click event due to frustrating event propagation issues across PW core
    // https://github.com/processwire/processwire-issues/issues/1028
    // .PageListActionSelect is the button 'Select' with appears when a page is clicked (no normally visible - loaded by js)
    $(document).on('mousedown', '.PageListActionSelect a', function (event) {
        var id_title;
        // Adapt unselect label to suit your language
        if ($(this).text() === 'Unselect') {
            id_title = '';
        } else {
            id_title = ($(this).closest('.PageListItem').children('.PageListPage').text()); // replace .text() by .attr('title') for path name
        }
        $('#id_title').val(id_title);
    });

    // For pagelistselectmultiple, get all the selected pages when the selection is updated
    // This returns the contents of the label displayed in the pagelist item. This can be set in your HannaCodeDialog::buildForm hook
    // The default is the page title. For the path name, set $f->labelFieldName = 'path'; in your hook
    $(document).on('change', '.InputfieldPageListSelectMultiple', function(event) {
        var id_title = [];
        $(this).find('.InputfieldContent ol li:not(.itemTemplate)').each(function(){
            id_title.push($(this).children('span.itemLabel').text())
        })
        $('#id_title').val(id_title);
    });

});

To hide the id_title attribute in the dialog, you need to add the following css:

#hanna-form .hide-field {
  display: none !important;
}

 

  • Like 3
Link to comment
Share on other sites

@Robin S - I have been using this module since it was released and always thought it was a necessary tool for inserting Hanna codes, but I just starting using some of its other features like: linked_page__pagelistselect

which makes it an entirely new beast - amazing.

Thanks!

  • Like 4
Link to comment
Share on other sites

Thanks for the report @adrian.

The newly released v0.3.6 adds support for ProcessProfile and ProcessUser, and also adds a config field to show the Tracy debug bar in the dialog which can be helpful for debugging if you are building the dialog form with a hook.

  • Like 4
Link to comment
Share on other sites

@Robin S - I am trying to offer selection of an uploaded file and not sure if I am taking the most efficient approach, but either way, it's not quite working. I am using https://processwire.com/modules/fieldtype-select-file/ to give me a InputfieldSelectFile

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {

    // The Hanna tag that is being opened in the dialog
    $tag_name = $event->arguments(0);

    // Other arguments if you need them
    /* @var Page $edited_page */
    $edited_page = $event->arguments(1); // The page open in Page Edit
    $current_attributes = $event->arguments(2); // The current attribute values
    $default_attributes = $event->arguments(3); // The default attribute values

    // The form rendered in the dialog
    /* @var InputfieldForm $form */
    $form = $event->return;

    if($tag_name === 'audio') {

        $modules = $event->wire('modules');

        /* @var InputfieldSelect $f */
        $f = $modules->InputfieldSelectFile;
        $f->name = 'selected_file';
        $f->id = 'selected_file';
        $f->label = 'Select File';
        $f->folderPath = 'assets/files/'.$edited_page->id.'/';
        $form->add($f);

    }

});

image.png.11df4fb41967af68a57ac2a557cd2b89.png

image.png.336021b43c2e6f894a7aa14cc420ce7f.png

All looks good so far, but then I end up with:

image.png.e54b3d00af90a7daf82b7ec16bad69ab.png

Any ideas what I might be doing wrong, or if there is a better way?

FYI, I had to change the root path in that File Select module to start at /site/ instead of /site/templates/

Thanks for any thoughts!

 

Link to comment
Share on other sites

4 minutes ago, adrian said:

I am using https://processwire.com/modules/fieldtype-select-file/ to give me a InputfieldSelectFile

If you're using non-core inputfields beyond those described in the module readme it will be a case of "your mileage may vary" and I can't really offer support for those kinds of cases.

I suggest just using a normal InputfieldSelect and setting the options from files in Files field(s) on the page, or via $files->find()/DirectoryIterator/glob.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
9 hours ago, Ivan Gretsky said:

Is it possible to use ckeditor as an inputfield for text?

No, CKEditor isn't a supported inputfield. I expect it would create rendering issues in the tag if it contains HTML, and if you are putting anything more than a short piece of text in your "read more" it would result in a huge, cumbersome tag widget.

Instead I think you should wrap the "read more" text in "open" and "close" Hanna tags.

[[rm-open]]
<p>Your text here.</p>
[[rm-close]]

Then replace the [[rm-open]] with a "Read more..." button and a div open tag, and the [[rm-close]] with a div close tag. Use JS to toggle the visibility of the div when the button is clicked.

You could also look at TextformatterPagination and TextformatterAccordion for inspiration but I think the above method would be the simplest.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
On 4/8/2021 at 3:18 AM, adrian said:

Ryan's update to the HannaCode module yesterday has broken this. Looks like it's probably just because he namespaced it, so should be an easy fix.

Thanks. The v0.3.0 update to HannaCode is actually a major refactoring of the module so there were a few things in HannaCodeDialog that needed updating for compatibility. The new v0.4.0 of HannaCodeDialog should be compatible with HannaCode v0.3.0 and it requires HannaCode >= v0.3.0.

  • Like 6
  • Thanks 2
Link to comment
Share on other sites

  • 2 months later...

@Robin S

I'm having some issues with getting this to work – using the latest PW, and Hanna Code, and Hanna Code Dialog; The field with the hanna codes (body) isn't wrapping the codes so they just look like text and don't get identified as widgets. Not sure what i'm doing wrong; Tried uninstalling everything and re-install, but since the upgrades, no widgets; The HCD was working fine before I upgraded it...

thanks for any insights you might have - looking forward to using this on a particular project..

Link to comment
Share on other sites

55 minutes ago, Macrura said:

The field with the hanna codes (body) isn't wrapping the codes so they just look like text and don't get identified as widgets.

That sounds like a JavaScript issue - have a look for errors in the browser console. I just checked with the latest PW/HannaCode/HannaCodeDialog and it all seems to be working here.

  • Like 1
Link to comment
Share on other sites

Thanks!! - i just did another test and figured out the problem – tt only recognizes the shortcodes if you have the Hanna Code textformatter applied to the field.

I'm not actually using Hanna Code, i'm processing the shortcodes with my own textformatter, but using your module to enable editing of my custom shortcodes...

In any case, you're right and it completely works now; I have the Hanna Code Textformatter after my textformatter so it won't do anything (the codes will all be processed by the time it hits that one)..

Link to comment
Share on other sites

@Macrura - thanks to @Robin S in another post: https://processwire.com/talk/topic/15902-hannacodedialog/?do=findComment&comment=208498

// add hanna code dialog to fields even though the Hanna code text formatter isn't applied
// https://processwire.com/talk/topic/15902-hannacodedialog/?do=findComment&comment=208498
$this->wire()->addHookAfter('InputfieldCKEditor::renderReadyHook', function (HookEvent $event) {
    $inputfield = $event->object;
    $field = $inputfield->hasField;
    // For your field name(s)...
    if(!$field || $field->name !== 'XXXX') return;
    $config_name = "InputfieldCKEditor_{$field->name}";
    $config_name_matrix = "InputfieldCKEditor_{$field->name}_matrix";
    $config = $this->wire('config');
    $js_config = $config->js();
    foreach($js_config as $key => $value) {
        if($key === $config_name || strpos($key, $config_name_matrix) === 0) {
            $js_config[$key]['extraPlugins'] .= ',hannadropdown,hannadialog';
            $config->js($key, $js_config[$key]);
        }
    }
});

 

  • Like 2
Link to comment
Share on other sites

Couple of questions and issues...

(1)

On 2/11/2021 at 5:35 PM, Robin S said:
		// Add JS file to Hanna Code Dialog form
		$js_file = $config->paths->templates . 'hannas/select_page.js';
		if(is_file($js_file)) {
			$js_url = $config->urls->templates . 'hannas/select_page.js?v=' . filemtime($js_file);
			$form->appendMarkup = "<script src='$js_url'></script>";
		}

For some reason I can't get this to work at all; not sure why but my hook is in ready.php, and the markup is not appended to the form. I put my js into ACF ProcessPageEdit.js and that works, but it would be interesting to know why the code above didn't work, in case i wanted to keep the js file along with my other hanna code stuff.

(2) I enabled Tracy in the form (module config), but not getting any tracy...not loading. Wondering if there is any way to troubleshoot that.

(3) The CK editor widget things are great, makes it much easier for editors to see where a code is, and of course double click it to edit parameters.
But one thing that is tricky is getting the cursor in front of a widget, if it is the first thing in the editor. For me no problem of course i can just switch to code mode and put in some placeholder in front of it; but for the average user, i do wonder if there is any solution to this...

thanks!

 

 

Link to comment
Share on other sites

5 hours ago, Macrura said:

the markup is not appended to the form

Double-check that the path to your JS file is correct, because that conditional will only append the script markup if is_file() is true. With some debugging (see item 2) hopefully you can get it working. I just tested here again and it works for me.

 

5 hours ago, Macrura said:

(2) I enabled Tracy in the form (module config), but not getting any tracy

The label of that config setting is perhaps not perfect - I'll update it. The setting doesn't actually ensure that Tracy is displayed, rather it only disables the default CSS in the module that would otherwise hide the Tracy debug bar.

<?php if(!$hcd->show_tracy): ?>
	#tracy-debug { display:none !important; }
<?php endif; ?>

So you first need to have Tracy set to display the debug bar in the PW admin generally and then if you have that HCD setting checked it won't be hidden in the dialog.

 

5 hours ago, Macrura said:

But one thing that is tricky is getting the cursor in front of a widget

There's not much I can do about that because it's just how the CKEditor Widget plugin works. In such a situation I tend to use the arrow keys to move the cursor to the start of the field, or type the text underneath and then drag the widget to its new position.

hcd.gif.8cc40b7f3866f2316e30199bd67d3352.gif

  • Like 1
Link to comment
Share on other sites

Many thanks for your post and help! All has been revealed, and some facepalm moments...

(1) had to change $config to wire('config') (?‍♂️)
(2) had to set Tracy config to show in dialog  (?‍♂️)
(3) Yep, i'll just tell people up front if they need to put something in front of it, they need to move the widget..

  • Like 1
Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...