question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve Theme functions

See original GitHub issue
  • Currently the themes class lacks functionality when it comes to handling checkboxes and radio inputs. (Might be more, but that’s the ones I’m focusing on at the moment)
  • Some functions needs to have access to more parameters. (#432 is a good example of this)
  • Several themes have different functionality (i.e. some support infoText option and other just ignore it)
  • There’s no way to customize themes at runtime other than overriding functions.

If anyone have worked on creating new themes or modified some of the existing, please post your comments on how we could improve this.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:26

github_iconTop GitHub Comments

3reactions
miranndacommented, Aug 5, 2019

image

image

1reaction
pmk65commented, Aug 11, 2019

@lukzas After I wrote the reply about afterInputReady, I updated the Spectre theme to get it to look nice with Select2 and Selectize using the afterInputReady to add/remove classes. The classes are not applied to the input element itself (Since Select2 and Selectice replaces that with a custom select), but on adjacent/sibling element (and it’s children)

Since afterInputReady is theme specific, you know where the label is based on the input field position. (I think the label element will be input.parentElement in Materialize theme)

I think this approach is better than adding extra code to the editors, like you did in #205. And also better than adding an extra parameter (Like I did for the getSelectInput ) It might be a little more complicated than just checking for a parameter, but this way we don’t have to change the theme functions (or add additional code to the editors).

Here’s an example from the Spectre theme.

  afterInputReady: function(input) {

    if (input.localName === 'select') {
      // Selectize adjustments
      if (input.classList.contains('selectized')) {
        var selectized = input.nextSibling;
        if (selectized) {
          // Remove Spectre class 'form-select' as this conflicts with Selectize styling
          selectized.classList.remove('form-select');
          $each(selectized.querySelectorAll('.form-select'), function(i, el) {
            el.classList.remove('form-select');
          });
        }
      }
      // Select2 ajustments
      else if (input.classList.contains('select2-hidden-accessible')) {
        var select2 = input.nextSibling,
            single = select2 && select2.querySelector('.select2-selection--single');
        // Add Spectre 'form-select' to single-select2 elements
        if (single) select2.classList.add('form-select');
      }
    }

    if (input.controlgroup) return;
    input.controlgroup = this.closest(input, '.form-group');
    if (this.closest(input, '.compact')) {
      input.controlgroup.style.marginBottom = 0;
    }
  },

The theme also contains some Inline Style Rules to maker further CSS adjustments to the Select2/Selectize boxes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

10 Basic Tips for Improving WordPress Themes - WebFX
10 Basic Tips for Improving WordPress Themes · 1. Reduce the Size of Theme Images · 2. Use a Custom Favicon · 3....
Read more >
Theme Functions - WordPress Developer Resources
Theme Setup · Automatic Feed Links · Navigation Menus · Load Text Domain · Post Thumbnails · Post Formats · Theme support in...
Read more >
How To Improve And Refine Your WordPress Theme ...
Take advantage of the hierarchy.. Keep code simple and manageable by moving repeated sections of code to their own template files. For example, ......
Read more >
10 Tips to Improve Your WordPress Theme - WPShout
10 Tips to Improve Your WordPress Theme · 1. Make your sidebar tabbed · 2. Create a widgetised footer that keeps visitors on...
Read more >
How to Customize Your WordPress Theme (5 Step-by ... - Kinsta
Need to change the look of your WordPress theme? Learn how to customize WordPress themes properly using one of the best methods (tutorial)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found