+ var content = this.text;
+
+ // Always work in normal text areas that currently have focus.
+ if (drupalSettings.tokenFocusedField && (drupalSettings.tokenFocusedField.tokenDialogFocus || drupalSettings.tokenFocusedField.tokenHasFocus)) {
+ insertAtCursor(drupalSettings.tokenFocusedField, content);
+ }
+ // Direct tinyMCE support.
+ else if (typeof(tinyMCE) != 'undefined' && tinyMCE.activeEditor) {
+ tinyMCE.activeEditor.execCommand('mceInsertContent', false, content);
+ }
+ // Direct CKEditor support. Only works if the field currently has focus,
+ // which is unusual since the dialog is open.
+ else if (typeof(CKEDITOR) != 'undefined' && CKEDITOR.currentInstance) {
+ CKEDITOR.currentInstance.insertHtml(content);
+ }
+ // WYSIWYG support, should work in all editors if available.
+ else if (Drupal.wysiwyg && Drupal.wysiwyg.activeId) {
+ Drupal.wysiwyg.instances[Drupal.wysiwyg.activeId].insert(content)
+ }
+ // CKeditor module support.
+ else if (typeof(CKEDITOR) != 'undefined' && typeof(Drupal.ckeditorActiveId) != 'undefined') {
+ CKEDITOR.instances[Drupal.ckeditorActiveId].insertHtml(content);
+ }
+ else if (drupalSettings.tokenFocusedField) {
+ insertAtCursor(drupalSettings.tokenFocusedField, content);