PluginProbe
codoc / 0.9.41
codoc v0.9.41
0.9.8.8 0.9.8.9 0.9.9 0.9.9.1 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.8.2 0.8.3 0.8.4 0.8.6 0.8.7 0.8.8 0.8.9 0.9 0.9.1 0.9.10 0.9.11 All 114 releases
codoc / src_mce / codoc-editor.js

codoc-editor.js in codoc 0.9.41, at src_mce/codoc-editor.js

105 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 const CODOC_URL = CODOCEDITOR.codoc_url;
3 const CODOC_USER_CODE = CODOCEDITOR.codoc_usercode;
4
5 tinymce.create('tinymce.plugins.Codoc', {
6 init: function (ed, url) {
7 // 表示用にタグを変換
8 ed.on( 'BeforeSetContent', function( event ) {
9 if ( event.content ) {
10 if ( event.content.indexOf( '<!-- wp:codoc/codoc-block' ) !== -1 ) {
11 moretext = "codoc";
12 title ="codoc";
13 event.content = event.content.replace( /(<!-- wp:codoc\/codoc-block[\s\S]*<!-- \/wp:codoc\/codoc-block -->)/g, function( match ) {
14 this.codocTag = match;
15 return '<img id="codoc-block-img" src="' + tinymce.Env.transparentSrc + '" data-wp-more="codoc" data-wp-more-text="' + moretext + '" ' +
16 'class="codoc-block" alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />';
17 });
18 }
19 }});
20 // 保存用にタグを変換
21 ed.on( 'PostProcess', function( event ) {
22 if ( event.get ) {
23 event.content = event.content.replace(/<img[^>]+>/g, function( image ) {
24 if ( image.indexOf( 'data-wp-more="codoc"' ) !== -1 ) {
25 return this.codocTag;
26 }
27 return image;
28 });
29 }
30 });
31 ed.addButton('codoc', {
32 title: 'codoc記事設定',
33 onclick: function () {
34 tb_show('codoc記事設定:', '#TB_inline');
35
36 jQuery.ajaxSetup({
37 cache: false,
38 });
39 let date = new Date;
40 let ymd = sprintf('%s%s%s',date.getYear(), date.getMonth(),date.getDate());
41 jQuery.getScript("https://codoc.jp/sdk/js/sdk.v1.js?ver=" + ymd, function(data, textStatus, jqxhr) {
42 //jQuery.getScript("https://codoc.jp/sdk/sdk/js/sdk.v1.js?ver=" + ymd, function(data, textStatus, jqxhr) {
43
44 let body = tinymce.activeEditor.getBody();
45 let util = new CodocUtil({ url: CODOC_URL, user_code: CODOC_USER_CODE, html: (window.codocTag ? window.codocTag : '') });
46
47 //貼付け時の挙動
48 util.registerSubmitHook(function(me){
49 var editor = tinymce.activeEditor;
50 editor.selection.collapse();
51 // すでにcodocタグがあるかどうか
52 if (jQuery(editor.dom.doc).find('.codoc-block')) {
53 // caret position を現在codocタグの位置に移動
54 editor.selection.select(jQuery(editor.dom.doc).find('.codoc-block')[0]);
55 // ブロックを一旦リセット
56 jQuery(editor.dom.doc).find('.codoc-block').remove();
57 }
58 // ブロックを作成
59 tinymce.activeEditor.execCommand('mceInsertRawHTML', false, me.blockHtml );
60
61 tb_remove();
62 });
63 // サブスクリプスションを取得
64 util.fetchSubscriptions(function(me,res){
65 // フォームを作成
66 let el = me.createForm('codoc-sdk');
67 me.write(el,document.getElementById('TB_ajaxContent'));
68 });
69
70 });
71 }});
72 },
73 createControl: function (n, cm) {
74 return null;
75 },
76 getInfo: function () {
77 return {
78 longname: 'codoc Shortcodes',
79 author: 'codoc.jp',
80 authorurl: 'codoc.jp',
81 infourl: '',
82 version: '1.0'
83 };
84 }
85 });
86
87 tinymce.PluginManager.add('codoc', tinymce.plugins.Codoc);
88
89 jQuery(document).on('click', '.return_codoc_shortcode', function () {
90 var id = jQuery(this).data('id');
91 tinyMCE.activeEditor.execCommand('mceInsertContent', 0, '[codoc id="' + id + '"]');
92 tb_remove();
93 });
94
95 jQuery(document).on('click', '.submit-codoc-form', function () {
96 // todo
97 //alert(CODOCEDITOR.nonce)
98 var url = 'admin-ajax.php?action=codoc_shortcodes&height=600&width=600&usercode=' + jQuery('#codoc-usercode')[0].value + '&entrycode=' + jQuery('#codoc-entrycode')[0].value + '&_wpnonce=' + CODOCEDITOR.nonce;
99 tb_show('codocの記事一覧:',url);
100 jQuery('#TB_window').addClass('codocTB');
101 });
102
103
104 })();
105