liquid_feedback_frontend

annotate env/ui/field/wysihtml.lua @ 1309:32cc544d5a5b

Cumulative patch for upcoming frontend version 4
author bsw/jbe
date Sun Jul 15 14:07:29 2018 +0200 (2018-07-15)
parents
children 56209dc74a9c
rev   line source
bsw/jbe@1309 1 function ui.field.wysihtml(args)
bsw/jbe@1309 2
bsw/jbe@1309 3 local toolbar = {
bsw/jbe@1309 4 { command = "bold", title ="CTRL+B", icon = "format_bold" },
bsw/jbe@1309 5 { command = "italic", title ="CTRL+I", icon = "format_italic" },
bsw/jbe@1309 6 { command = "createLink", icon = "insert_link" },
bsw/jbe@1309 7 { command = "removeLink", icon = "insert_link", crossed = "\\" },
bsw/jbe@1309 8 { command = "formatBlock", command_value = "h1", icon = "title", head_level = "1" },
bsw/jbe@1309 9 { command = "formatBlock", command_value = "h2", icon = "title", head_level = "2" },
bsw/jbe@1309 10 { command = "formatBlock", command_value = "h3", icon = "title", head_level = "3" },
bsw/jbe@1309 11 { command = "formatBlock", command_blank = "true", icon = "format_clear" },
bsw/jbe@1309 12 { command = "insertBlockQuote", icon = "format_quote" },
bsw/jbe@1309 13 { command = "insertUnorderedList", icon = "format_list_bulleted" },
bsw/jbe@1309 14 { command = "insertOrderedList", icon = "format_list_numbered" },
bsw/jbe@1309 15 { command = "outdentList", icon = "format_indent_decrease" },
bsw/jbe@1309 16 { command = "indentList", icon = "format_indent_increase" },
bsw/jbe@1309 17 -- { command = "alignLeftStyle", icon = "format_align_left" },
bsw/jbe@1309 18 -- { command = "alignRightStyle", icon = "format_align_right" },
bsw/jbe@1309 19 -- { command = "alignCenterStyle", icon = "format_align_center" },
bsw/jbe@1309 20 { command = "undo", icon = "undo" },
bsw/jbe@1309 21 { command = "redo", icon = "redo" }
bsw/jbe@1309 22 }
bsw/jbe@1309 23
bsw/jbe@1309 24 slot.put([[
bsw/jbe@1309 25 <style>
bsw/jbe@1309 26 #wysihtml-html-button {
bsw/jbe@1309 27 padding: 2px;
bsw/jbe@1309 28 vertical-align: bottom;
bsw/jbe@1309 29 }
bsw/jbe@1309 30 #wysihtml-html-button.wysihtml-action-active {
bsw/jbe@1309 31 color: #fff;
bsw/jbe@1309 32 background: #000;
bsw/jbe@1309 33 }
bsw/jbe@1309 34 </style>
bsw/jbe@1309 35 ]])
bsw/jbe@1309 36
bsw/jbe@1309 37 ui.container{ attr = { id = "toolbar", class = "toolbar", style = "display: none;" }, content = function()
bsw/jbe@1309 38 for i, t in ipairs(toolbar) do
bsw/jbe@1309 39 ui.tag{ tag = "a", attr = { ["data-wysihtml-command"] = t.command, ["data-wysihtml-command-value"] = t.command_value, ["data-wysihtml-command-blank-value"] = t.command_blank, title = t.shortcut }, content = function()
bsw/jbe@1309 40 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = t.icon }
bsw/jbe@1309 41 if t.crossed then
bsw/jbe@1309 42 ui.tag{ attr = { class = "crossed" }, content = t.crossed }
bsw/jbe@1309 43 end
bsw/jbe@1309 44 if t.head_level then
bsw/jbe@1309 45 ui.tag{ attr = { class = "head_level" }, content = t.head_level }
bsw/jbe@1309 46 end
bsw/jbe@1309 47 end }
bsw/jbe@1309 48 end
bsw/jbe@1309 49 slot.put([[
bsw/jbe@1309 50 <div data-wysihtml-dialog="createLink" style="display: none;">
bsw/jbe@1309 51 <label>
bsw/jbe@1309 52 Link:
bsw/jbe@1309 53 <input data-wysihtml-dialog-field="href" value="http://">
bsw/jbe@1309 54 </label>
bsw/jbe@1309 55 <a data-wysihtml-dialog-action="save">OK</a>&nbsp;<a data-wysihtml-dialog-action="cancel">Cancel</a>
bsw/jbe@1309 56 </div>
bsw/jbe@1309 57 ]])
bsw/jbe@1309 58 slot.put([[ <a id="wysihtml-html-button" data-wysihtml-action="change_view">]] .. _"expert editor (HTML)" .. [[</a> ]])
bsw/jbe@1309 59 end }
bsw/jbe@1309 60
bsw/jbe@1309 61 ui.field.text(args)
bsw/jbe@1309 62
bsw/jbe@1309 63 ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.js" }, content = "" }
bsw/jbe@1309 64 ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.all-commands.js" }, content = "" }
bsw/jbe@1309 65 ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.toolbar.js" }, content = "" }
bsw/jbe@1309 66 ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml_liquidfeedback_rules.js" }, content = "" }
bsw/jbe@1309 67 ui.script{ script = [[
bsw/jbe@1309 68 function initEditor() {
bsw/jbe@1309 69 var editor = new wysihtml.Editor("]] .. args.attr.id .. [[", {
bsw/jbe@1309 70 toolbar: "toolbar",
bsw/jbe@1309 71 parserRules: wysihtmlParserRules,
bsw/jbe@1309 72 useLineBreaks: true
bsw/jbe@1309 73 });
bsw/jbe@1309 74 }
bsw/jbe@1309 75 if(window.addEventListener){
bsw/jbe@1309 76 window.addEventListener('load', initEditor, false);
bsw/jbe@1309 77 } else {
bsw/jbe@1309 78 window.attachEvent('onload', initEditor);
bsw/jbe@1309 79 }
bsw/jbe@1309 80 ]] }
bsw/jbe@1309 81
bsw/jbe@1309 82 end
bsw/jbe@1309 83

Impressum / About Us