Skip to content

Commit

Permalink
Rewrite init() so it accepts initialized plugins instead of object-names
Browse files Browse the repository at this point in the history
fixes #10
  • Loading branch information
SjonHortensius committed Feb 22, 2016
1 parent eb3c941 commit d051d6a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Using LRTEditor is easy; include the files and configure the highlighter:
window.addEventListener('load', function(){
LRTEditor.initialize(
document.getElementsByTagName('code')[0],
['MinimalPlugin', 'UndoPlugin', 'HighlightPlugin'],
[LRTEditor_MinimalPlugin, LRTEditor_UndoPlugin, LRTEditor_HighlightPlugin],
{
highlightCallback: function(el){ sh_highlightElement(el, sh_languages['php']); },
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
window.addEventListener('load', function(){
LRTEditor.initialize(
document.getElementsByTagName('code')[0],
['MinimalPlugin', 'UndoPlugin', 'HighlightPlugin'],
[LRTEditor_MinimalPlugin, LRTEditor_UndoPlugin, LRTEditor_HighlightPlugin],
{
highlightCallback: function(el){ sh_highlightElement(el, sh_languages['php']); },
}
Expand Down
12 changes: 8 additions & 4 deletions src/LRTEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ var LRTEditor = {};
highlightCallback: function(){}
};

this.initialize = function(el, _plugins, c)
this.initialize = function(el, plugins, c)
{
this.element = el;

for (var k in c)
this.config[k] = c[k];

_plugins.forEach(function(p){
plugins[p] = window['LRTEditor_' +p];
for (var p in plugins)
{
// fallback for strings instead of objects, fixes #10
if ('object' != typeof plugins[p])
plugins[p] = window['LRTEditor_' +plugins[p]];

plugins[p].initialize(this);
}.bind(this));
}

this.element.setAttribute('contentEditable', 'true');
this.element.setAttribute('autoComplete', 'off');
Expand Down

0 comments on commit d051d6a

Please sign in to comment.