Created
November 28, 2014 09:12
-
-
Save siamkreative/e29ea4f4d761a4185494 to your computer and use it in GitHub Desktop.
A simple script to check whether TinyMCE is active and visible in WordPress Dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function ($) { | |
'use strict'; | |
/* | |
References | |
http://codeblow.com/questions/method-to-check-whether-tinymce-is-active-in-wordpress/ | |
https://wordpress.org/support/topic/tinymceactiveeditorgetcontentcontent-does-not-work-with-tinymce-advanced | |
*/ | |
var tinymceActive, cannedResponse, editorType; | |
/* This is an object passed using wp_localize_script that returns either "tinymce" or "html" (from wp_get_user_setting) */ | |
editorType = wpascr.editor; | |
$('.wpas-canned-response').click(function (e) { | |
e.preventDefault(); | |
tinymceActive = (typeof tinyMCE != 'undefined') && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden(); | |
cannedResponse = $(this).attr('data-message'); | |
/* Check if TinyMCE is active */ | |
if (tinymceActive) { | |
/* Check version of TinyMCE */ | |
if (tinymce.majorVersion < 4) { | |
tinyMCE.execInstanceCommand('wpas_reply', 'mceInsertContent', false, cannedResponse); | |
} else { | |
var edv4 = tinyMCE.get('wpas_reply'); | |
edv4.insertContent(cannedResponse); | |
} | |
} else { | |
/* Append canned response to existing textarea value */ | |
$('#wpas_reply').val(function (i, val) { | |
return val + cannedResponse; | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment