scloader.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * This file is part of the ForkBB <https://github.com/forkbb>.
  3. *
  4. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  5. * @license The MIT License (MIT)
  6. */
  7. if (typeof ForkBB === "undefined" || !ForkBB) {
  8. var ForkBB = {};
  9. }
  10. ForkBB.editor = (function (doc, win) {
  11. 'use strict';
  12. var instance,
  13. dataName = "data-SCEditorConfig",
  14. emotName = "data-smiliesEnabled",
  15. selector = "textarea[" + dataName + "]",
  16. textarea,
  17. options = {
  18. format: 'bbcode',
  19. icons: 'monocons',
  20. style: '',
  21. emoticonsCompat: true,
  22. emoticonsEnabled: false,
  23. resizeWidth: false,
  24. width: '100%',
  25. toolbar: 'bold,italic,underline,strike,subscript,superscript|' +
  26. 'left,center,right,justify|font,size,color,removeformat|' +
  27. 'bulletlist,orderedlist,indent,outdent|' +
  28. 'table|code,quote|horizontalrule,image,email,link,unlink|' +
  29. 'emoticon,date,time|maximize,source'
  30. };
  31. function initEditor()
  32. {
  33. var conf, smiliesEnabled;
  34. if (
  35. !sceditor
  36. || !(textarea = doc.querySelector(selector))
  37. || !(conf = JSON.parse(textarea.getAttribute(dataName)))
  38. ) {
  39. return;
  40. }
  41. options = Object.assign(options, conf);
  42. smiliesEnabled = '1' == textarea.getAttribute(emotName);
  43. if (!smiliesEnabled) {
  44. options.toolbar = options.toolbar.replace(/\bemoticon\b/, '').replace(/[^\w]*\|[^\w]*/g, '|').replace(/,{2,}/g, ',') ;
  45. }
  46. sceditor.create(textarea, options);
  47. instance = sceditor.instance(textarea);
  48. if (smiliesEnabled) {
  49. var checkbox = doc.querySelector('input[name="hide_smilies"]');
  50. if (checkbox) {
  51. checkbox.addEventListener('change', function (e) {
  52. instance.emoticons(!e.target.checked);
  53. });
  54. instance.emoticons(!checkbox.checked);
  55. } else {
  56. instance.emoticons(true);
  57. }
  58. }
  59. }
  60. return {
  61. init : function () {
  62. initEditor();
  63. },
  64. };
  65. }(document, window));
  66. if (document.addEventListener && Object.assign) {
  67. document.addEventListener("DOMContentLoaded", ForkBB.editor.init, false);
  68. }