liquid_feedback_frontend
view env/ui/field/wysihtml.lua @ 1815:6246f8249f9f
Actually handle the unique violation
| author | bsw | 
|---|---|
| date | Thu Dec 02 13:35:38 2021 +0100 (2021-12-02) | 
| parents | fce3409bc9b0 | 
| children | 71916d0badca | 
 line source
     1 function ui.field.wysihtml(args)
     3   local toolbar = {
     4     { command = "bold", title ="CTRL+B", icon = "format_bold" },
     5     { command = "italic", title ="CTRL+I", icon = "format_italic" },
     6     { command = "createLink", icon = "insert_link" },
     7     { command = "removeLink", icon = "insert_link", crossed = "\\" },
     8 --    { command = "insertImage", icon = "insert_image" },
     9     { command = "formatBlock", command_value = "h1", icon = "title", head_level = "1" },
    10     { command = "formatBlock", command_value = "h2", icon = "title", head_level = "2" },
    11     { command = "formatBlock", command_value = "h3", icon = "title", head_level = "3" },
    12     { command = "formatBlock", command_blank = "true", icon = "format_clear" },
    13     { command = "insertBlockQuote", icon = "format_quote" },
    14     { command = "insertUnorderedList", icon = "format_list_bulleted" },
    15     { command = "insertOrderedList", icon = "format_list_numbered" },
    16     { command = "outdentList", icon = "format_indent_decrease" },
    17     { command = "indentList", icon = "format_indent_increase" },
    18 --    { command = "alignLeftStyle", icon = "format_align_left" },
    19 --    { command = "alignRightStyle", icon = "format_align_right" },
    20 --    { command = "alignCenterStyle", icon = "format_align_center" },
    21     { command = "undo", icon = "undo" },
    22     { command = "redo", icon = "redo" }
    23   }
    25   slot.put([[
    26     <style>
    27       #wysihtml-html-button {
    28         padding: 2px;
    29         vertical-align: bottom;
    30       }
    31       #wysihtml-html-button.wysihtml-action-active {
    32         color: #fff;
    33         background: #000;
    34       }
    35     </style>
    36   ]])
    38   ui.container{ attr = { id = "toolbar", class = "toolbar", style = "display: none;" }, content = function()
    39     for i, t in ipairs(toolbar) do
    40       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()
    41         ui.tag{ tag = "i", attr = { class = "material-icons" }, content = t.icon }
    42         if t.crossed then
    43           ui.tag{ attr = { class = "crossed" }, content = t.crossed }
    44         end
    45         if t.head_level then
    46           ui.tag{ attr = { class = "head_level" }, content = t.head_level }
    47         end
    48       end }
    49     end
    50     slot.put([[
    51       <div data-wysihtml-dialog="createLink" style="display: none;">
    52         <label>
    53           Link:
    54           <input data-wysihtml-dialog-field="href" value="http://">
    55         </label>
    56         <a data-wysihtml-dialog-action="save">OK</a> <a data-wysihtml-dialog-action="cancel">Cancel</a>
    57       </div>
    59       <div data-wysihtml-dialog="insertImage" style="display: none;">
    60         <label>
    61           Image:
    62           <input data-wysihtml-dialog-field="src" value="http://">
    63         </label>
    64         <label>
    65           Align:
    66           <select data-wysihtml-dialog-field="className">
    67             <option value="">default</option>
    68             <option value="wysiwyg-float-left">left</option>
    69             <option value="wysiwyg-float-right">right</option>
    70           </select>
    71         </label>
    72         <a data-wysihtml-dialog-action="save">OK</a> <a data-wysihtml-dialog-action="cancel">Cancel</a>
    73       </div>
    75     ]])
    76     slot.put([[      <a id="wysihtml-html-button" data-wysihtml-action="change_view">]] .. _"expert editor (HTML)" .. [[</a> ]])
    77   end }
    79   ui.field.text(args)
    81   ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.js" }, content = "" }
    82   ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.all-commands.js" }, content = "" }
    83   ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.toolbar.js" }, content = "" }
    84   ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml_liquidfeedback_rules.js" }, content = "" }
    85   ui.script{ script = [[
    86     function initEditor() {
    87       var editor = new wysihtml.Editor("]] .. args.attr.id .. [[", {
    88         toolbar:       "toolbar",
    89         parserRules:   wysihtmlParserRules,
    90         useLineBreaks: true
    91       });
    92     }
    93     if(window.addEventListener){
    94       window.addEventListener('load', initEditor, false);
    95     } else {
    96       window.attachEvent('onload', initEditor);
    97     }
    98   ]] }
   100 end
