Skip to content

Instantly share code, notes, and snippets.

@devyfriend
Created January 10, 2022 04:45
Show Gist options
  • Save devyfriend/5036af481775d429b11154742362321a to your computer and use it in GitHub Desktop.
Save devyfriend/5036af481775d429b11154742362321a to your computer and use it in GitHub Desktop.
Summernote plugin
$.extend(true, $.summernote.lang, {
"en-US": {
/* US English(Default Language) */
linkPlugin: {
exampleText: "Example Text",
dialogTitle: "Example Plugin",
okButton: "OK",
},
},
});
$.extend($.summernote.options, {
linkPlugin: {
icon: '<i class="note-icon-pencil"/>',
tooltip: "Example Plugin Tooltip",
},
});
$.extend($.summernote.plugins, {
linkPlugin: function (context) {
var self = this,
ui = $.summernote.ui,
$note = context.layoutInfo.note,
$editor = context.layoutInfo.editor,
$editable = context.layoutInfo.editable,
$toolbar = context.layoutInfo.toolbar,
options = context.options,
lang = options.langInfo,
$container = options.dialogsInBody ? $(document.body) : $editor,
footer =
'<button href="#" class="btn btn-primary note-linkPlugin-btn">' +
lang.linkPlugin.okButton +
"</button>",
body = '<div class="form-group"></div>';
context.memo("button.linkPlugin", function () {
var button = ui.button({
contents: options.linkPlugin.icon,
tooltip: lang.linkPlugin.tooltip,
click: function (e) {
context.invoke("linkPlugin.show");
},
});
return button.render();
});
this.$dialog = ui
.dialog({
title: lang.linkPlugin.dialogTitle,
body: body,
footer: footer,
})
.render()
.appendTo($container);
this.destroy = function () {
ui.hideDialog(this.$dialog);
this.$dialog.remove();
};
/*
this.bindEnterKey = function ($input, $btn) {
$input.on("keypress", function (event) {
if (event.keyCode === 13) $btn.trigger("click");
});
};
this.bindLabels = function () {
self.$dialog.find(".form-control:first").focus().select();
self.$dialog.find("label").on("click", function () {
$(this).parent().find(".form-control:first").focus();
});
};
*/
this.show = function () {
// var $img = $($editable.data("target"));
var editorInfo = {};
this.showlinkPluginDialog(editorInfo).then(function (
editorInfo
) {
ui.hideDialog(self.$dialog);
$note.val(context.invoke("code"));
$note.change();
});
};
this.showlinkPluginDialog = function (editorInfo) {
return $.Deferred(function (deferred) {
ui.onDialogShown(self.$dialog, function () {
context.triggerEvent("dialog.shown");
/*
$editBtn.click(function (e) {
e.preventDefault();
deferred.resolve({});
});
self.bindEnterKey($editBtn);
self.bindLabels();
*/
});
ui.onDialogHidden(self.$dialog, function () {
$editBtn.off("click");
if (deferred.state() === "pending") deferred.reject();
});
ui.showDialog(self.$dialog);
});
};
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment