From dbdab012cf48af334401df39fe24c59f2b44e572 Mon Sep 17 00:00:00 2001 From: Damien Jones Date: Thu, 2 Nov 2017 10:51:35 -0600 Subject: [PATCH 1/2] Fixes issue #17 --- src/angular-markdown-editor.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/angular-markdown-editor.js b/src/angular-markdown-editor.js index 4fff5ea..6732502 100644 --- a/src/angular-markdown-editor.js +++ b/src/angular-markdown-editor.js @@ -11,6 +11,12 @@ angular if (! element.hasClass('processed')) { element.addClass('processed'); + // if the directive was called after document.ready, e.g. because of ng-if then the element + // will not have been initialized by bootstrap-markdown + if (element.markdown === undefined){ + element.data('markdown', (data = new $.fn.markdown.Constructor(element[0], {}))) + } + // Setup the markdown WYSIWYG. element.markdown({ autofocus: options.autofocus || false, From 4ddb0fea7676063347202f4dfa50bf923b2de5a1 Mon Sep 17 00:00:00 2001 From: Damien Jones Date: Thu, 2 Nov 2017 15:14:28 -0600 Subject: [PATCH 2/2] When explicitely constructing the markdown editor the options should be passed in. --- src/angular-markdown-editor.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/angular-markdown-editor.js b/src/angular-markdown-editor.js index 6732502..d3d38a2 100644 --- a/src/angular-markdown-editor.js +++ b/src/angular-markdown-editor.js @@ -11,14 +11,7 @@ angular if (! element.hasClass('processed')) { element.addClass('processed'); - // if the directive was called after document.ready, e.g. because of ng-if then the element - // will not have been initialized by bootstrap-markdown - if (element.markdown === undefined){ - element.data('markdown', (data = new $.fn.markdown.Constructor(element[0], {}))) - } - - // Setup the markdown WYSIWYG. - element.markdown({ + var markdownOptions = { autofocus: options.autofocus || false, saveable: options.saveable || false, savable: options.savable || false, @@ -69,7 +62,17 @@ angular runScopeFunction(scope, attrs.onShow, e); } } - }); + }; + + // Setup the markdown WYSIWYG. + + // if the markdown editor was added dynamically the markdown function will be undefined + // so it has to be called explicitely + if (element.markdown === undefined){ + element.data('markdown', (data = new $.fn.markdown.Constructor(element[0], markdownOptions))) + } else { + element.markdown(markdownOptions); + } } } };