element_script.erl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. -module(element_script).
  2. %%-author('Vladimir Galunshchikov').
  3. -include_lib("nitro/include/nitro.hrl").
  4. -export([
  5. render_element/1
  6. ]).
  7. render_element(Record) when Record#script.show_if == false -> [<<>>];
  8. render_element(Record) ->
  9. List = [
  10. %% global
  11. {<<"accesskey">>, Record#script.accesskey},
  12. {<<"class">>, Record#script.class},
  13. {<<"contenteditable">>,
  14. case Record#script.contenteditable of
  15. true -> "true";
  16. false -> "false";
  17. _ -> []
  18. end},
  19. {<<"contextmenu">>, Record#script.contextmenu},
  20. {<<"dir">>,
  21. case Record#script.dir of
  22. ltr -> "ltr";
  23. rtl -> "rtl";
  24. auto -> "auto";
  25. _ -> []
  26. end},
  27. {<<"draggable">>,
  28. case Record#script.draggable of
  29. true -> "true";
  30. false -> "false";
  31. _ -> []
  32. end},
  33. {<<"dropzone">>, Record#script.dropzone},
  34. {<<"hidden">>,
  35. case Record#script.hidden of
  36. true -> "hidden";
  37. _ -> []
  38. end},
  39. {<<"id">>, Record#script.id},
  40. {<<"lang">>, Record#script.lang},
  41. {<<"spellcheck">>,
  42. case Record#script.spellcheck of
  43. true -> "true";
  44. false -> "false";
  45. _ -> []
  46. end},
  47. {<<"style">>, Record#script.style},
  48. {<<"tabindex">>, Record#script.tabindex},
  49. {<<"title">>, Record#script.title},
  50. {<<"translate">>,
  51. case Record#script.contenteditable of
  52. true -> "yes";
  53. false -> "no";
  54. _ -> []
  55. end},
  56. %% spec
  57. {<<"async">>,
  58. case Record#script.async of
  59. true -> "async";
  60. _ -> []
  61. end},
  62. {<<"charset">>, Record#script.charset},
  63. {<<"defer">>,
  64. case Record#script.defer of
  65. true -> "defer";
  66. _ -> []
  67. end},
  68. {<<"src">>, Record#script.src},
  69. {<<"type">>, Record#script.type} | Record#script.data_fields
  70. ],
  71. wf_tags:emit_tag(<<"script">>,
  72. case Record#script.src of
  73. [] -> nitro:render(Record#script.body);
  74. _ -> []
  75. end, List).