mercredi 1 juillet 2015

Creating a editor

I'm trying to understand object inheritance in JS with an exercise, create a online editor, like this one that i'm writing on.

But.. i'm a little confuse here, i want use data-* to manipulate my editor:

<div class="editor__wrapper">
 <div data-editor="toolbar">
 </div>
 <textarea data-editor="textarea"></textarea>
</div>

So, i was trying initialize like this:

$(window).on('load', function() {
 $('[data-editor]').each(function() {
  var element = $(this);

   var editor = new Editor(element);
 });
});

and the editor:

var Editor = function(element) {
 this.element = element;
};

But this is not what i exactly want here..

I want initialize with data-* but create a toolbar if is a toolbar and create an editor if is an editor, but make the two inherit from the a father with commum properties.

I'm little lost here, what you guys think about this? There is a better way???

Thanks.

Aucun commentaire:

Enregistrer un commentaire