Last active
December 29, 2015 19:48
-
-
Save fumikito/7719231 to your computer and use it in GitHub Desktop.
WordPressのエディタに対してiframe内からテキスト要素を追加ビジュアルエディタかHTMLエディタかを判別しつつ、最後にカーソルがあった位置に挿入する。ついでにthickboxを閉じる
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($){ | |
| // ショートコード挿入 | |
| $('.button-shortcode').click(function(e){ | |
| e.preventDefault(); | |
| // ex. ショートコードの値 | |
| var shortcode = $(this).prev('input').val(), | |
| mce = window.parent.tinyMCE; | |
| if( mce.activeEditor && !(mce.activeEditor.isHidden()) ){ | |
| // TinyMCEがオープンならそれを使う | |
| window.parent.tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, shortCode ) | |
| }else if(window.parent.QTags){ | |
| // なければQTagでやってみる | |
| window.parent.QTags.insertContent(shortCode); | |
| } | |
| // ThickBoxを閉じる | |
| window.parent.tb_remove(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment