liquid_feedback_frontend

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/env/ui/field/wysihtml.lua	Sun Jul 15 14:07:29 2018 +0200
     1.3 @@ -0,0 +1,83 @@
     1.4 +function ui.field.wysihtml(args)
     1.5 +  
     1.6 +  local toolbar = {
     1.7 +    { command = "bold", title ="CTRL+B", icon = "format_bold" },
     1.8 +    { command = "italic", title ="CTRL+I", icon = "format_italic" },
     1.9 +    { command = "createLink", icon = "insert_link" },
    1.10 +    { command = "removeLink", icon = "insert_link", crossed = "\\" },
    1.11 +    { command = "formatBlock", command_value = "h1", icon = "title", head_level = "1" },
    1.12 +    { command = "formatBlock", command_value = "h2", icon = "title", head_level = "2" },
    1.13 +    { command = "formatBlock", command_value = "h3", icon = "title", head_level = "3" },
    1.14 +    { command = "formatBlock", command_blank = "true", icon = "format_clear" },
    1.15 +    { command = "insertBlockQuote", icon = "format_quote" },
    1.16 +    { command = "insertUnorderedList", icon = "format_list_bulleted" },
    1.17 +    { command = "insertOrderedList", icon = "format_list_numbered" },
    1.18 +    { command = "outdentList", icon = "format_indent_decrease" },
    1.19 +    { command = "indentList", icon = "format_indent_increase" },
    1.20 +--    { command = "alignLeftStyle", icon = "format_align_left" },
    1.21 +--    { command = "alignRightStyle", icon = "format_align_right" },
    1.22 +--    { command = "alignCenterStyle", icon = "format_align_center" },
    1.23 +    { command = "undo", icon = "undo" },
    1.24 +    { command = "redo", icon = "redo" }
    1.25 +  }
    1.26 +
    1.27 +  slot.put([[
    1.28 +    <style>
    1.29 +      #wysihtml-html-button {
    1.30 +        padding: 2px;
    1.31 +        vertical-align: bottom;
    1.32 +      }
    1.33 +      #wysihtml-html-button.wysihtml-action-active {
    1.34 +        color: #fff;
    1.35 +        background: #000;
    1.36 +      }
    1.37 +    </style>
    1.38 +  ]])
    1.39 +  
    1.40 +  ui.container{ attr = { id = "toolbar", class = "toolbar", style = "display: none;" }, content = function()
    1.41 +    for i, t in ipairs(toolbar) do
    1.42 +      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()
    1.43 +        ui.tag{ tag = "i", attr = { class = "material-icons" }, content = t.icon }
    1.44 +        if t.crossed then
    1.45 +          ui.tag{ attr = { class = "crossed" }, content = t.crossed }
    1.46 +        end
    1.47 +        if t.head_level then
    1.48 +          ui.tag{ attr = { class = "head_level" }, content = t.head_level }
    1.49 +        end
    1.50 +      end }
    1.51 +    end
    1.52 +    slot.put([[
    1.53 +      <div data-wysihtml-dialog="createLink" style="display: none;">
    1.54 +        <label>
    1.55 +          Link:
    1.56 +          <input data-wysihtml-dialog-field="href" value="http://">
    1.57 +        </label>
    1.58 +        <a data-wysihtml-dialog-action="save">OK</a>&nbsp;<a data-wysihtml-dialog-action="cancel">Cancel</a>
    1.59 +      </div>
    1.60 +    ]])
    1.61 +    slot.put([[      <a id="wysihtml-html-button" data-wysihtml-action="change_view">]] .. _"expert editor (HTML)" .. [[</a> ]])
    1.62 +  end }
    1.63 +  
    1.64 +  ui.field.text(args)
    1.65 +
    1.66 +  ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.js" }, content = "" }
    1.67 +  ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.all-commands.js" }, content = "" }
    1.68 +  ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml.toolbar.js" }, content = "" }
    1.69 +  ui.tag{ tag = "script", attr = { src = request.get_absolute_baseurl() .. "static/wysihtml/wysihtml_liquidfeedback_rules.js" }, content = "" }
    1.70 +  ui.script{ script = [[
    1.71 +    function initEditor() {
    1.72 +      var editor = new wysihtml.Editor("]] .. args.attr.id .. [[", {
    1.73 +        toolbar:       "toolbar",
    1.74 +        parserRules:   wysihtmlParserRules,
    1.75 +        useLineBreaks: true
    1.76 +      });
    1.77 +    }
    1.78 +    if(window.addEventListener){
    1.79 +      window.addEventListener('load', initEditor, false);
    1.80 +    } else {
    1.81 +      window.attachEvent('onload', initEditor);
    1.82 +    }
    1.83 +  ]] }
    1.84 +
    1.85 +end
    1.86 +      

Impressum / About Us