Skip to content

Commit

Permalink
Added custom Summernote library (wip, currently inactive)
Browse files Browse the repository at this point in the history
  • Loading branch information
muratcakir committed Nov 23, 2024
1 parent 600179e commit 62bae4e
Show file tree
Hide file tree
Showing 62 changed files with 8,406 additions and 22 deletions.
9 changes: 9 additions & 0 deletions src/Smartstore.Web/Infrastructure/AdminBundles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public void RegisterBundles(IApplicationContext appContext, IBundleCollection bu

/* Summernote--> /bundle/js/summernote.js
-----------------------------------------------------*/
//var summernote = "/lib/editors/summernote2/";
//bundles.Add(new ScriptBundle("/bundle/js/summernote.js").Include(
// summernote + "summernote-sm.js",
// summernote + "plugins/smartstore.tablestyles.js",
// summernote + "plugins/smartstore.cssclass.js",
// lib + "beautify/beautify.min.js",
// lib + "beautify/beautify-css.min.js",
// lib + "beautify/beautify-html.min.js",
// summernote + "globalinit.js"));
var summernote = "/lib/editors/summernote/";
bundles.Add(new ScriptBundle("/bundle/js/summernote.js").Include(
summernote + "summernote-bootstrap.min.js",
Expand Down
1 change: 1 addition & 0 deletions src/Smartstore.Web/wwwroot/admin/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@import "../lib/colorpicker/scss/colorpicker";
@import "../lib/datetimepicker/scss/tempusdominus";
@import "../lib/editors/summernote/scss/summernote";
//@import "../lib/editors/summernote2/scss/summernote";


//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
$.extend(true, $.summernote.lang, {
'de-DE': { /* German */
attrs: {
cssClass: 'CSS Klasse',
cssStyle: 'CSS Stil',
rel: 'Rel',
},
link: {
browse: 'Durchsuchen'
},
image: {
imageProps: 'Bild Eigenschaften'
},
tableStyles: {
tooltip: "Tabellenstil",
stylesExclusive: ["Standard", "Eingerahmt"],
stylesInclusive: ["Streifen", "Kompakt", "Hover Effekt"]
},
imageShapes: {
tooltip: 'Stil',
tooltipShapeOptions: ['Responsiv', 'Rahmen', 'Abgerundet', 'Kreis', 'Thumbnail', 'Schatten (klein)', 'Schatten (mittel)', 'Schatten (gro&szlig)']
}
}
'de-DE': { /* German */
common: {
ok: 'OK',
cancel: 'Abbrechen'
},
font: {
code: 'Code'
},
attrs: {
cssClass: 'CSS Klasse',
cssStyle: 'CSS Stil',
rel: 'Rel',
},
link: {
browse: 'Durchsuchen'
},
image: {
imageProps: 'Bild Eigenschaften'
},
tableStyles: {
tooltip: "Tabellenstil",
stylesExclusive: ["Standard", "Eingerahmt"],
stylesInclusive: ["Streifen", "Kompakt", "Hover Effekt"]
},
imageShapes: {
tooltip: 'Stil',
tooltipShapeOptions: ['Responsiv', 'Rahmen', 'Abgerundet', 'Kreis', 'Thumbnail', 'Schatten (klein)', 'Schatten (mittel)', 'Schatten (gro&szlig)']
}
}
});
237 changes: 237 additions & 0 deletions src/Smartstore.Web/wwwroot/lib/editors/summernote2/globalinit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
let summernote_global_config;
let summernote_image_upload_url;

(function () {
const beautifyOpts = {
indent_size: 2,
indent_with_tabs: true,
indent_char: " ",
max_preserve_newlines: "2",
preserve_newlines: true,
keep_array_indentation: false,
break_chained_methods: false,
indent_scripts: "normal",
brace_style: "collapse",
space_before_conditional: true,
unescape_strings: false,
jslint_happy: false,
end_with_newline: false,
wrap_line_length: "140",
indent_inner_html: true,
comma_first: false,
e4x: false,
indent_empty_lines: false
};

summernote_global_config = {
disableDragAndDrop: false,
dialogsInBody: true,
container: 'body',
dialogsFade: true,
height: 300,
prettifyHtml: true,
popatmouse: true,
hideArrow: false,
recordEveryKeystroke: false,
// TODO: Turn on spellCheck again
spellCheck: false,
callbacks: {
onBlurCodeview(code, e) {
// Summernote does not update WYSIWYG content on codable blur,
// only when switched back to editor
$(this).val(code);
},
//onFileBrowse(e, mediaType, deferred) {
// Smartstore.media.openFileManager({
// el: e.target,
// type: mediaType,
// backdrop: false,
// onSelect: (files) => {
// if (!files.length) {
// deferred.reject();
// }
// else {
// deferred.resolve(files[0].url);
// }
// }
// });
//},
onImageUpload(files) {
if (summernote_image_upload_url) {
sendFile(files[0], this);
}
},
onSanitizeHtml(html, opts) {
if (opts.prettify && window.html_beautify) {
return window.html_beautify(html, beautifyOpts);
}
return html;
}
},
toolbar: [
['edit', ['undo', 'redo']],
['text', ['bold', 'italic', 'underline', 'moreFontStyles']],
//['color', ['forecolor', 'backcolor']],
//['font', ['fontname', 'x-color', 'fontsize']],
['para', ['style', 'cssclass', 'ul', 'ol', 'paragraph', 'clear', 'cleaner']],
['insert', ['link', 'image', 'video', 'table', 'hr']],
['view', ['codeview', 'fullscreen', 'help']]
],
popover: {
image: [
['custom', ['imageAttributes', 'link', 'unlink', 'imageShapes']],
['imagesize', ['resizeFull', 'resizeHalf', 'resizeQuarter', 'resizeNone']],
['float', ['floatLeft', 'floatRight', 'floatNone']],
['remove', ['removeMedia']]
],
link: [
['link', ['linkDialogShow', 'unlink']]
],
table: [
['add', ['addRowDown', 'addRowUp', 'addColLeft', 'addColRight']],
['delete', ['deleteRow', 'deleteCol', 'deleteTable']],
['custom', ['tableStyles']]
],
air: [
['color', ['color']],
['font', ['bold', 'underline', 'clear']],
['para', ['ul', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture']]
]
},
styleTags: [
'p',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'pre',
{ title: 'Blockquote', tag: 'blockquote', className: 'blockquote', value: 'blockquote' }
],
imageAttributes: {
icon: '<i class="fa fa-pencil"/>',
removeEmpty: true, // true = remove attributes | false = leave empty if present
disableUpload: true // true = don't display Upload Options | Display Upload Options
}
};

if (CodeMirror?.hint) {
const cmOptions = summernote_global_config.codemirror = {
mode: "htmlmixed",
theme: "eclipse",
lineNumbers: true,
lineWrapping: false,
tabSize: 2,
indentWithTabs: true,
smartIndent: true,
matchTags: true,
matchBrackets: true,
autoCloseTags: true,
autoCloseBrackets: true,
styleActiveLine: true,
hintOptions: {
closeCharacters: /[\s()\[\]{};:>,.|%]/,
completeSingle: false
}
};

if (CodeMirror?.hint) {
cmOptions.extraKeys = {
"'.'": CodeMirror.hint.completeAfter,
"'<'": CodeMirror.hint.completeAfter,
"'/'": CodeMirror.hint.completeIfAfterLt,
"' '": CodeMirror.hint.completeIfAfterSpace,
"'='": CodeMirror.hint.completeIfInTag,
"Ctrl-Space": "autocomplete",
"F11": function (cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); },
"Esc": function (cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); }
}
}
}

function sendFile(file, editor, welEditable) {
data = new FormData();
data.append("file", file);
data.append("a", "UPLOAD");
data.append("d", "file");
data.append("ext", true);

$.ajax({
data: data,
type: "POST",
url: summernote_image_upload_url,
cache: false,
contentType: false,
processData: false,
success: function (result) {
if (result.Success) {
$(editor).summernote('insertImage', result.Url);
}
else {
EventBroker.publish("message", {
title: 'Image upload error',
text: result.Message,
type: 'error',
hide: false
});
}
}
});
}
})();

// Initialize summernote
$(function () {

// Extend base language
$.extend(true, $.summernote.lang, {
'en-US': {
common: {
ok: 'OK',
cancel: 'Cancel'
},
font: {
code: 'Code'
},
attrs: {
cssClass: 'CSS Class',
cssStyle: 'CSS Style',
rel: 'Rel',
},
link: {
browse: 'Browse'
},
image: {
imageProps: 'Image Attributes'
},
imageShapes: {
tooltip: 'Shape',
tooltipShapeOptions: ['Responsive', 'Border', 'Rounded', 'Circle', 'Thumbnail', 'Shadow (small)', 'Shadow (medium)', 'Shadow (large)']
},
tableStyles: {
tooltip: "Table style",
stylesExclusive: ["Basic", "Bordered"],
stylesInclusive: ["Striped", "Condensed", "Hoverable"]
}
}
});

// Custom events
// Editor toggling
$(document).on('click', '.note-editor-preview', function (e) {
var div = $(this);
var textarea = $(div.data("target"));
var lang = div.data("lang");

div.remove();
textarea
.removeClass('d-none')
.summernote($.extend(true, {}, summernote_global_config, { lang: lang, focus: true }));
});

// Fix "CodeMirror too wide" issue
$(document).on('click', '.note-toolbar .btn-codeview', function (e) {
var wrapper = $(this).closest('.adminData');
if (wrapper.length) {
wrapper.css('overflow-x', $(this).is('.active') ? 'auto' : '');
}
});
});
Loading

0 comments on commit 62bae4e

Please sign in to comment.