Skip to content

Commit

Permalink
Merge pull request heyanlong#9 from shaunfreeman/shaunfreeman-patch-2
Browse files Browse the repository at this point in the history
fixed multiple code blocks when dialog dismised
  • Loading branch information
何延龙 authored Sep 18, 2017
2 parents 9d76f68 + e3224d3 commit 4716f97
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/summernote-ext-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
var $editor = context.layoutInfo.editor;
var options = context.options;
var lang = options.langInfo;

// add button

context.memo('button.highlight', function () {
Expand Down Expand Up @@ -85,11 +85,11 @@

this.createCodeNode = function (code, select) {
var $code = $('<code>');
$code.html(code);
$code.html($code);
$code.addClass('language-' + select);

var $pre = $('<pre>');
$pre.html($code)
$pre.html(code)
$pre.addClass('prettyprint').addClass('linenums');

return $pre[0];
Expand All @@ -102,26 +102,29 @@
var $extHighlightSelect = self.$dialog.find('.ext-highlight-select');

ui.onDialogShown(self.$dialog, function () {
context.triggerEvent('dialog.shown');

$extHighlightCode.val(codeInfo);

$extHighlightCode.on('input', function () {
ui.toggleBtn($extHighlightBtn, $extHighlightCode.val() != '');

codeInfo = $extHighlightCode.val();
});

$extHighlightBtn.one('click', function (event) {
event.preventDefault();
deferred.resolve(self.createCodeNode(codeInfo, $extHighlightSelect.val()));

self.$dialog.modal('hide');
deferred.resolve(self.createCodeNode($extHighlightCode.val(), $extHighlightSelect.val()));
});
});


ui.onDialogHidden(self.$dialog, function () {
$extHighlightBtn.off('click');
if (deferred.state() === 'pending') {
deferred.reject();
}
});

ui.showDialog(self.$dialog);
}).promise();
});
};

this.getCodeInfo = function () {
Expand All @@ -131,11 +134,14 @@

this.show = function () {
var codeInfo = self.getCodeInfo();

context.invoke('editor.saveRange');
this.showHighlightDialog(codeInfo).then(function (codeInfo) {
self.$dialog.modal('hide');
context.invoke('editor.restoreRange');
context.invoke('editor.insertNode', codeInfo);

if (codeInfo) {
context.invoke('editor.insertNode', codeInfo);
}
});
};

Expand Down

0 comments on commit 4716f97

Please sign in to comment.