juek / CustomSections

Developer plugin for rapid prototyping of custom section types in Typesetter CMS
GNU General Public License v2.0
3 stars 7 forks source link

announcing some refactoring #16

Closed juek closed 7 years ago

juek commented 7 years ago

Time to start some cleanup and refactoring. editor.js is close to 1000 lines. This is what I'm planning:

1st: Modularity in editor.js --> gp_editor.controls will become an object (of methods) like

gp_editor.controls = { 
  input_field : function(control_map, item, value){
    // generate the control jQuery object...
    return control;
  },
  other_control : function(control_map, item, value){
    // generate the control jQuery object...
    return control;
  }. 
 // ...
};

This way we start modularization by using...

$.extend(gp_editor, {
  mySpecialControlFunction : function(args){
    // do sth.
  },
  controls : {
      my_special_control : function(control_map, item, value){
        // generate the control jQuery object...
        control.find("button").on("click", gp_editor.mySpecialControlFunction );
        return control;
      } 
   }
});

... loaded from a separate script

juek commented 7 years ago

@a2exfr , this refactoring will cause some changes to existing section types (mainly control_type naming from dashes to underscores, as you already did in wise foresight ;-) Should I open a new branch? I'm not yet experienced with merging branches.

a2exfr commented 7 years ago

I'm not yet experienced with merging branches.

me too ) I even do not know how to made my fork identical without removing it and forked again) so it's up to you. But this a big cnange may be new branch is logical decision. I'm will try to help with code if I be able too)

About Modularity: Interesting, have you many more controls type in mind? Currently my needs in control types is mostly satisfied. Actually even link field is a combination of existing controls - input. ck-finder and checkbox :)

juek commented 7 years ago

Interesting, have you many more controls type in mind?

No, actually not. But they will certainly come with special situations. And I want an easy way to integrate them into universal editor without changing it's code.

E.g. Multi-Date - this is merely a test case for more complex controls (with multi-dimensional arrays and dynamic element count). It is quite code-bloating. I will build this one as an extension (or module). It's mostly done but I'm currently still thinking about a useful module definition, where we can define all component dependencies, possible thirdparty libs and css.

I want to have editor modules/extensions in separate folders (like types) for easy exchange and maintenability. Universal editor files and CustomSections.php should remain completely untouched. Not exactly trivial...

a2exfr commented 7 years ago

I just look at multi-date and now understand for what this modularity for. multi-date is very specific control type it is not be used so offen as input or chekbox

juek commented 7 years ago

parallel thinking/writing LOL