Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

javascript - How can a11ychecker run process on content after CKEDITOR.dom.element change?

I am trying to tag number strings and date strings with class span.numberstring|span.datestring such that CKeditor A11ychecker plugin will find them and render a Quickfix form to populate <abbr title> attribute with screen-readable text. I use the following script to run a regex search when 'beforeCommandExec' equals 'a11ychecker'. After editor contents is replaced, the 'CKEDITOR.dom.element' shows as 'null' and the error response is: plugin.js?t=K87C:32 Uncaught TypeError: Cannot read property 'getPosition' of null

txtGroupEditor.on('beforeCommandExec',function(event){

               var commandName = event.data.name;

            if(commandName == 'a11ychecker'){

                var dataRegex=/([0-9]{4,4})(?!</span>)/g,

                string=this.getData(),

                m;

                do {
                   m = dataRegex.exec(string);

                    if (m) {

                        string=string.replace(m[0],'<span class="numberstring">' + m[0] + '</span>');

                    }

                } while (m);

                this.setData(string);
            }
        });

Is this a timing issue? I have tried firing the a11ychecker process after the regex operation is completed, but that does not work either and it still seems to unbind itself from the instance. Thank you, in advance, for the help.

Result without regex operation

Result without regex operation

Result with regex operation

Result with regex operation

question from:https://stackoverflow.com/questions/65926245/how-can-a11ychecker-run-process-on-content-after-ckeditor-dom-element-change

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Conclusion: Forcing two operations to run, in sequence (tagging then a11ychecker) when clicking on a11ychecker button, appears to have its challenges.

Solution: Breaking out the tagging operation into its own button appears to be more effective and reliable. Now, tagging operation is required to run before enabling the a11ychecker button. When the editor contents is activated on 'key' down, the a11ychecker button will be disabled to assume that content has been altered and should be run through the tagging operation again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...