Detection of jquery.tinymce.js

jasimon9
jasimon9 used Ask the Experts™
on
We have a "browser test page" which is used to diagnose user problems. There are fields the user can fill out, plus quite a few detections as well. The data from that page can then be emailed into our tech support. The page is at http://www.rephunter.net/test-browser.php. The current page is no longer fully functional, for the following reason:

I have just converted the website from using dojo to jquery. Part of the test includes checking for tinymce support. We used to run the "regular" tinymce library, but have switched over to the jquery version. In the previous version, which used an older version of TinyMCE, support was tested by the following:

    if(typeof tinyMCE == 'undefined')

However, with the new instance of tinymce, it always comes up as undefined, even if there is a tinymce editor on the page. I have done some testing and it appears that tinyMCE is defined only after the form is submitted. For example, here is a snippet that shows how this works:


    <head>
    <script type="text/javascript">
          alert('head tinymce=' + typeof tinyMCE);
          function Validate()
          {
                alert('validate tinymce=' + typeof tinyMCE);
                if (tinyMCE)
                      alert('tinymce is defined');
          }f
    </script>
    </head>
   
    <body>
    form onsubmit='Validate()'>
    <textarea class="tinymce"></textarea>
    <input type="submit" />
    </form>
    <script type="text/javascript">
          alert('body tinymce=' + typeof tinyMCE);
    </script>

No matter what I have done in the detection program, the only way to get a valid tinyMCE object seems to be to submit the page. That is, the 'body' alert does not work; the "validate" alert does.

One workaround is to put on the page instructions for the user to look at the page and see if there is an editor rather than just a textarea. However, with our users this would be less than ideal. We really want the email, and thus I need to have a way to detect tinyMCE.

I may be able to work this out by having an onsubmit function that detects tinymce, but I would also like something that can be displayed directly to the user on first display of the page.

Is there a simple solution? Something similar to the elegance of if(typeof tinyMCE == 'undefined')


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
Try running the test in your document-ready section.  That way you give a chance for the code to load before you look for it.

$(document).ready(function() {
   alert('body tinymce=' + typeof tinyMCE);
});

Open in new window

Commented:
The above is similar to what I had been trying. However, the approach will not work because of the way tinymce is defined in the plugin. Here is what does work:

if (typeof jQuery.fn.tinymce == 'undefined')

The essense here being the addition of the jQuery.fn to the object name.

Splitting points.

Author

Commented:
While contributors solution was along the right lines, the real problem was the name that needed to be used.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial