Jump to content

Module(tte): InputfieldURLChecker


tpr
 Share

Recommended Posts

InputfieldURLChecker

This is a tiny module to add a URL check button to InputfieldURL. It's live, meaning that it opens what you just typed in, and visible only if the field is non-empty. It's as unobtrusive as can :)

Modules directory

GitHub

It would be the best if something similar would be built-in to PW.

post-3156-0-39566700-1445099748_thumb.gi

There will be probably some tweaks and settings in the future. Suggestions welcome (even for module name).

Edited by tpr
  • Like 10
Link to comment
Share on other sites

v0.7 is ready. Download link in the first post.

Configuration

post-3156-0-44779500-1445162194_thumb.pn

Changelog

  • fixed link height when URL field is under admin tab (works with ajax-loaded tabs)
  • fixed link height when first tab didn't have any URL field
  • namespaced JS
  • new option: ctrl+shift+click and ctrl+shift+enter modes
  • new option: force http prefix
  • new option: limit module to list of enabled fields

What I plan to add in the future is opening links in a lightbox, and perhaps allowing all 3 modes to be used at the same time. But I think I'll do these only if there's a demand.

  • Like 2
Link to comment
Share on other sites

It's still a modulette compared to other heavyweight modules :)

The first post contains the link to the GitHub page (v0.8). There was a small code optimization but otherwise it's the same as v0.7.

  • Like 1
Link to comment
Share on other sites

Hi,

a very useful Modul(ette). :)

Primarily, it is not the "amount" of code what tells about the "weight" of a module. :lol:

------

BTW, when having a look at Github, I spotted DIRECTORY_SEPARATOR in URLs for script and style loading. Shouldn't it be a simple / (slash) instead?

  • Like 1
Link to comment
Share on other sites

Thanks! DIRECTORY_SEPARATOR was indeed unnecessary, I guess it was a victim of a copy-paste operation :)

Unfortunately there were other bugs to fix. Just realized there are ajax-loaded FIELDS too and not only tabs. Now these are covered too (v0.85).

Positioning of the links was improved too, and fixed the issue when the field had description or notes.

Later I'll add enabled_templates function to make it more versatile, plus make field value clickable if the field is set to "closed + locked".

If I knew there are so many field options to take into account I probably won't start this module :)

  • Like 2
Link to comment
Share on other sites

I was about to ask help here but finally solved things on my own (and looking into other modules).

v0.92 allows using the module on all admin pages. So far it was only added to pages where ProcessPageEdit could hook to, so for example now it is available on other modules's settings pages, or the new module install screen:

InputfieldURLChecker.gif

New (default) option was added: button-left - this is handier because the button is not on the far-right end of the input.

Also the appearance was changed a bit: colored arrow appears only on hover, otherwise remains gray. The button itself is visible all the time, even if the field is empty.

The height of the button was also fixed by adding a dummy url field on start, just to measure its height (and then it's removed). Other measurements were unfortunately buggy.

I'm still looking for a better module name, though I kinda like the abbreviation "TUF", which is used heavily in the JS for naming.

Locked fields got an underline on hover, just to make them more usable.

  • Like 2
Link to comment
Share on other sites

Okay, settled with "InputfieldURLChecker" as the module name as I found no better one.

In the last few days the module got some major updates:

  • allow button and hotkey modes to be used together
  • asmSelect fields for enabled fields/templates
  • add "placeholder" to asmSelect fields
  • make strings translatable (with __FILE__ textdomain)
  • JS optimizations/fixes

Check the github repo for the details - the options page screenshot shows most of them.

  • Like 4
Link to comment
Share on other sites

I'm experimenting with loading the URL in an iframe, sliding in from the right side of the browser window. It works in most cases but fails if the target site's X-Frame-Options is set to SAMEORIGIN, like here on this forum. Unfortunately this is something that cannot be check on the client side. However, I will keep this feature with a note in the readme.

post-3156-0-85631800-1445866999_thumb.gi

Link to comment
Share on other sites

  • 4 weeks later...

I'm not having any luck getting this to work... no arrow is shown;

I'm on Mac, Firefox, Chrome, but no luck;

templates and fields all setup....

no js errors..

Any idea what might be the cause, or how to troubleshoot?

TIA

Link to comment
Share on other sites

I just installed from the module directory (entered the classname "InputfieldURLChecker") and worked fine.

I'm on Win but I don't think that could be an issue. What FF/Chrome versions are you using?

I guess you tried it on az URL type field and not on a regular InputfieldText.

In the module settings, have you added anything to the "Enabled templates" and "Enabled fields" area? If so, the module will be active only in those templates/fields, and unavailable elsewhere.

Also make sure the Mode is set to "Button" and not hotkey.

On the admin page where you expect the button to appear, check the page source if it contains "IUC"  within a script tag in the head.

Link to comment
Share on other sites

hey tpr - thanks and also let me thank you for this module, it looks great, and you have put a lot of work into it - it will be really handy for this project i'm working on where we need to check that links to external sites are working/correct!

So i checked everything and troubleshot it to where i have narrowed down the issue to the field restriction - if that is set, then it doesn't work; setting the template restriction works... being that i don't really need to restrict by field, i'm all good, but i can further assist with this issue if you need more info.

thanks again!

  • Like 1
Link to comment
Share on other sites

I will rewrite half of the module to take advantage of InputfieldUrl::render, which would make things simpler. Now JavaScript makes all the heavyweight stuff which works, but it's too clunky here and there.

  • Like 1
Link to comment
Share on other sites

Just committed v1.1.0 to the dev branch at GitHub:

https://github.com/rolandtoth/InputfieldURLChecker/tree/dev

This is 99% the same in functionality but under the hood it uses InputfieldURL::render and InputfieldURL::renderValue.

The only new feature is that locked field urls now respect the module setting "Target", so clicking on them may open in an iframe if setting so.

Locked url fields with description or notes was linkified incorrectly in the previous (JS-only) version, as all the field contents were wrapped in a link, not only the url. Now it's handled beautifully with the renderValue hook.

Using backend hooks made it much simpler and reliable to deal with template/field restrictions, and probably there will be more benefits in further developments.

  • Like 4
Link to comment
Share on other sites

  • 8 months later...

Is there a way to specify array in field name? I have this in getDefaultData:

static public function getDefaultData() {
        return array(
            'InputfieldURLChecker'         => array(
                'IUC_mode'              => array(
                    'button'
                ),
                'IUC_button_position'   => 'button-left',
                'IUC_target'            => 'new-window',
                'IUC_force_http'        => 1,
                'IUC_enabled_templates' => array(),
                'IUC_enabled_fields'    => array()
            )
	)
}

Now if I make a  field and set its name to 'IUC_mode' and save the module, the $data in getModuleConfigInputfields($data) will NOT have 'IUC_mode' under 'InputfieldURLChecker' (but a flat array).

I have tried this, but no joy:

$f = wire('modules')->get('InputfieldCheckboxes');
$f->name = 'InputfieldURLChecker["IUC_mode"]';
...

 

Link to comment
Share on other sites

  • 2 years later...

Hi @tpr.

Thanks for the module.

I have spent some time to understand why the module doesn't work and the issue is that only ProcessPageEdit and ProcessProfile processes are allowed.

But I have several process modules that handle page edit of custom page types.  It would be great if we could control this option in the module config.

There is $modules->findByPrefix("), so maybe you can provide such options with ASM select by $modules->findByPrefix("Process");

Thanks. 

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...