From 7b25b9cf1ab144ab23c28059dd03dd25b690eefd Mon Sep 17 00:00:00 2001 From: Slava <53832230+slavalamp@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:16:07 +0100 Subject: [PATCH 1/2] AO3-2898 update character count from tinymce --- public/javascripts/mce_editor.js | 8 ++++++++ public/javascripts/mce_editor.min.js | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/public/javascripts/mce_editor.js b/public/javascripts/mce_editor.js index 2985a92bcba..b631fee3c61 100644 --- a/public/javascripts/mce_editor.js +++ b/public/javascripts/mce_editor.js @@ -74,6 +74,14 @@ tinyMCE.init({ // As of version 5.0, TinyMCE has a very limited mobile version it inflicts on Android and iOS phones by default. // This forces the desktop version. Note that this is only implicitly documented and may break. theme: "silver", + }, + + setup: function (editor) { + // Update character count when switching to and editing in TinyMCE + editor.on('init change undo redo', function() { + editor.save(); + $j(editor.targetElm).trigger('change'); + }) } }); diff --git a/public/javascripts/mce_editor.min.js b/public/javascripts/mce_editor.min.js index e0ff7c1b85c..005f130b2f8 100644 --- a/public/javascripts/mce_editor.min.js +++ b/public/javascripts/mce_editor.min.js @@ -1,3 +1 @@ -tinyMCE.init({branding:!1,plugins:"directionality hr image link lists paste tabfocus",contextmenu:!1,menubar:!1,toolbar:"paste | bold italic underline strikethrough | link unlink image | blockquote | hr | bullist numlist | alignleft aligncenter alignright alignjustify | undo redo | ltr rtl",browser_spellcheck:!0,inline_styles:!1,convert_urls:!1,content_css:"/stylesheets/tiny_mce_custom.css?"+new Date().getTime(),tabfocus_elements:"tinymce",extended_valid_elements:"b, i, span[!class|!dir], strike, u",invalid_elements:"font",formats:{alignleft:{selector:'div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li',attributes:{align:'left'}},aligncenter:{selector:'div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li',attributes:{align:'center'}},alignright:{selector:'div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li',attributes:{align:'right'}},alignjustify:{selector:'div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li',attributes:{align:'justify'}},underline:{inline:'u',exact:!0},strikethrough:[{inline:'strike',exact:!0},{inline:'s',remove:"all"},{inline:'del',remove:"all"}]},paste_word_valid_elements:"@[align],-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br",target_list:[{title:'None',value:''}],mobile:{theme:"silver",}});function addEditor(id){tinyMCE.execCommand('mceAddEditor',!1,id)} -function removeEditor(id){tinyMCE.execCommand('mceRemoveEditor',!1,id)} -$j(document).ready(function(){$j(".rtf-html-switch").removeClass('hidden');$j(".html-link").addClass('current');$j(".rtf-link").click(function(event){addEditor('content');$j(this).addClass('current');$j('.rtf-notes').removeClass('hidden');$j('.html-link').removeClass('current');$j('.html-notes').addClass('hidden');event.preventDefault()});$j('.html-link').click(function(event){removeEditor('content');$j(this).addClass('current');$j('.html-notes').removeClass('hidden');$j('.rtf-link').removeClass('current');$j('.rtf-notes').addClass('hidden');event.preventDefault()})}) +function addEditor(e){tinyMCE.execCommand("mceAddEditor",!1,e)}function removeEditor(e){tinyMCE.execCommand("mceRemoveEditor",!1,e)}tinyMCE.init({branding:!1,plugins:"directionality hr image link lists paste tabfocus",contextmenu:!1,menubar:!1,toolbar:"paste | bold italic underline strikethrough | link unlink image | blockquote | hr | bullist numlist | alignleft aligncenter alignright alignjustify | undo redo | ltr rtl",browser_spellcheck:!0,inline_styles:!1,convert_urls:!1,content_css:"/stylesheets/tiny_mce_custom.css?"+(new Date).getTime(),tabfocus_elements:"tinymce",extended_valid_elements:"b, i, span[!class|!dir], strike, u",invalid_elements:"font",formats:{alignleft:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"left"}},aligncenter:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"center"}},alignright:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"right"}},alignjustify:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"justify"}},underline:{inline:"u",exact:!0},strikethrough:[{inline:"strike",exact:!0},{inline:"s",remove:"all"},{inline:"del",remove:"all"}]},paste_word_valid_elements:"@[align],-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br",target_list:[{title:"None",value:""}],mobile:{theme:"silver"},setup:function(e){e.on("init change undo redo",function(){e.save(),$j(e.targetElm).trigger("change")})}}),$j(document).ready(function(){$j(".rtf-html-switch").removeClass("hidden"),$j(".html-link").addClass("current"),$j(".rtf-link").click(function(e){addEditor("content"),$j(this).addClass("current"),$j(".rtf-notes").removeClass("hidden"),$j(".html-link").removeClass("current"),$j(".html-notes").addClass("hidden"),e.preventDefault()}),$j(".html-link").click(function(e){removeEditor("content"),$j(this).addClass("current"),$j(".html-notes").removeClass("hidden"),$j(".rtf-link").removeClass("current"),$j(".rtf-notes").addClass("hidden"),e.preventDefault()})}); From e947854b805d553f6fb5bb26ba884dd05336852c Mon Sep 17 00:00:00 2001 From: Slava <53832230+slavalamp@users.noreply.github.com> Date: Mon, 27 Jan 2025 15:29:48 +0100 Subject: [PATCH 2/2] AO3-2898 use getElement() method instead of undocumented property --- public/javascripts/mce_editor.js | 2 +- public/javascripts/mce_editor.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/javascripts/mce_editor.js b/public/javascripts/mce_editor.js index ca2b778ef5d..25ac0ab0a5a 100644 --- a/public/javascripts/mce_editor.js +++ b/public/javascripts/mce_editor.js @@ -80,7 +80,7 @@ tinyMCE.init({ // Update character count when switching to and editing in TinyMCE editor.on('init change undo redo', function() { editor.save(); - $j(editor.targetElm).trigger('change'); + $j(editor.getElement()).trigger('change'); }); } }); diff --git a/public/javascripts/mce_editor.min.js b/public/javascripts/mce_editor.min.js index 005f130b2f8..2732f17ac5e 100644 --- a/public/javascripts/mce_editor.min.js +++ b/public/javascripts/mce_editor.min.js @@ -1 +1 @@ -function addEditor(e){tinyMCE.execCommand("mceAddEditor",!1,e)}function removeEditor(e){tinyMCE.execCommand("mceRemoveEditor",!1,e)}tinyMCE.init({branding:!1,plugins:"directionality hr image link lists paste tabfocus",contextmenu:!1,menubar:!1,toolbar:"paste | bold italic underline strikethrough | link unlink image | blockquote | hr | bullist numlist | alignleft aligncenter alignright alignjustify | undo redo | ltr rtl",browser_spellcheck:!0,inline_styles:!1,convert_urls:!1,content_css:"/stylesheets/tiny_mce_custom.css?"+(new Date).getTime(),tabfocus_elements:"tinymce",extended_valid_elements:"b, i, span[!class|!dir], strike, u",invalid_elements:"font",formats:{alignleft:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"left"}},aligncenter:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"center"}},alignright:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"right"}},alignjustify:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"justify"}},underline:{inline:"u",exact:!0},strikethrough:[{inline:"strike",exact:!0},{inline:"s",remove:"all"},{inline:"del",remove:"all"}]},paste_word_valid_elements:"@[align],-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br",target_list:[{title:"None",value:""}],mobile:{theme:"silver"},setup:function(e){e.on("init change undo redo",function(){e.save(),$j(e.targetElm).trigger("change")})}}),$j(document).ready(function(){$j(".rtf-html-switch").removeClass("hidden"),$j(".html-link").addClass("current"),$j(".rtf-link").click(function(e){addEditor("content"),$j(this).addClass("current"),$j(".rtf-notes").removeClass("hidden"),$j(".html-link").removeClass("current"),$j(".html-notes").addClass("hidden"),e.preventDefault()}),$j(".html-link").click(function(e){removeEditor("content"),$j(this).addClass("current"),$j(".html-notes").removeClass("hidden"),$j(".rtf-link").removeClass("current"),$j(".rtf-notes").addClass("hidden"),e.preventDefault()})}); +function addEditor(e){tinyMCE.execCommand("mceAddEditor",!1,e)}function removeEditor(e){tinyMCE.execCommand("mceRemoveEditor",!1,e)}tinyMCE.init({branding:!1,plugins:"directionality hr image link lists paste tabfocus",contextmenu:!1,menubar:!1,toolbar:"paste | bold italic underline strikethrough | link unlink image | blockquote | hr | bullist numlist | alignleft aligncenter alignright alignjustify | undo redo | ltr rtl",browser_spellcheck:!0,inline_styles:!1,convert_urls:!1,content_css:"/stylesheets/tiny_mce_custom.css?"+(new Date).getTime(),tabfocus_elements:"tinymce",extended_valid_elements:"b, i, span[!class|!dir], strike, u",invalid_elements:"font",formats:{alignleft:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"left"}},aligncenter:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"center"}},alignright:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"right"}},alignjustify:{selector:"div, h1, h2, h3, h4, h5, h6, img, p, table, td, th, ul, ol, li",attributes:{align:"justify"}},underline:{inline:"u",exact:!0},strikethrough:[{inline:"strike",exact:!0},{inline:"s",remove:"all"},{inline:"del",remove:"all"}]},paste_word_valid_elements:"@[align],-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br",target_list:[{title:"None",value:""}],mobile:{theme:"silver"},setup:function(e){e.on("init change undo redo",function(){e.save(),$j(e.getElement()).trigger("change")})}}),$j(document).ready(function(){$j(".rtf-html-switch").removeClass("hidden"),$j(".html-link").addClass("current"),$j(".rtf-link").click(function(e){addEditor("content"),$j(this).addClass("current"),$j(".rtf-notes").removeClass("hidden"),$j(".html-link").removeClass("current"),$j(".html-notes").addClass("hidden"),e.preventDefault()}),$j(".html-link").click(function(e){removeEditor("content"),$j(this).addClass("current"),$j(".html-notes").removeClass("hidden"),$j(".rtf-link").removeClass("current"),$j(".rtf-notes").addClass("hidden"),e.preventDefault()})}); \ No newline at end of file