TinyMCE Templates - Version 4.3.1

Version Description

  • Bug fix on quick tags view.
Download this release

Release Info

Developer miyauchi
Plugin Icon 128x128 TinyMCE Templates
Version 4.3.1
Comparing to
See all releases

Code changes from version 4.2.0 to 4.3.1

css/tinymce-templates.css ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #tinymce-templates-backdrop {
2
+ display: none;
3
+ position: fixed;
4
+ top: 0;
5
+ left: 0;
6
+ right: 0;
7
+ bottom: 0;
8
+ min-height: 360px;
9
+ background: #000;
10
+ opacity: .7;
11
+ z-index: 159900;
12
+ }
13
+ #tinymce-templates-wrap {
14
+ display: none;
15
+ position: absolute;
16
+ width: 100%;
17
+ z-index: 999999;
18
+ }
19
+ #tinymce-templates-wrap .modal {
20
+ width: 90%;
21
+ max-width: 800px;
22
+ background-color: #ffffff;
23
+ margin: 0 auto;
24
+ box-sizing: border-box;
25
+ }
26
+ #tinymce-templates-wrap .modal .header {
27
+ background-color: #f5f5f5;
28
+ border-bottom: 1px solid #dedede;
29
+ padding: 10px 20px;
30
+ position: relative;
31
+ }
32
+ #tinymce-templates-wrap .modal .header h1 {
33
+ font-size: 16px;
34
+ margin: 0;
35
+ }
36
+ #tinymce-templates-wrap .modal .header .close {
37
+ position: absolute;
38
+ top: 10px;
39
+ right: 20px;
40
+ text-decoration: none;
41
+ color: #555555;
42
+ }
43
+ #tinymce-templates-wrap .modal .container {
44
+ padding: 10px 20px;
45
+ }
46
+ #tinymce-templates-wrap .modal .footer {
47
+ padding: 20px;
48
+ background-color: #f5f5f5;
49
+ border-top: 1px solid #dedede;
50
+ overflow: auto;
51
+ }
52
+ #tinymce-templates-wrap #tinymce-templates-preview {
53
+ border: none;
54
+ margin: 10px 0;
55
+ padding: 0;
56
+ border: 1px solid #dedede;
57
+ width: 100%;
58
+ }
59
+ #tinymce-templates-wrap #tinymce-templates-message {
60
+ display: none;
61
+ float: left;
62
+ }
63
+ #tinymce-templates-wrap #tinymce-templates-insert {
64
+ display: block;
65
+ float: right;
66
+ }
css/tinymce-templates.less ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #tinymce-templates-backdrop
2
+ {
3
+ display: none;
4
+ position: fixed;
5
+ top: 0;
6
+ left: 0;
7
+ right: 0;
8
+ bottom: 0;
9
+ min-height: 360px;
10
+ background: #000;
11
+ opacity: .7;
12
+ z-index: 159900;
13
+ }
14
+
15
+ #tinymce-templates-wrap
16
+ {
17
+ display: none;
18
+ position: absolute;
19
+ width: 100%;
20
+ z-index: 999999;
21
+
22
+ .modal
23
+ {
24
+ width: 90%;
25
+ max-width: 800px;
26
+ background-color: #ffffff;
27
+ margin: 0 auto;
28
+ box-sizing: border-box;
29
+
30
+ .header
31
+ {
32
+ background-color: #f5f5f5;
33
+ border-bottom: 1px solid #dedede;
34
+ padding: 10px 20px;
35
+ position: relative;
36
+
37
+ h1
38
+ {
39
+ font-size: 16px;
40
+ margin: 0;
41
+ }
42
+
43
+ .close
44
+ {
45
+ position: absolute;
46
+ top: 10px;
47
+ right: 20px;
48
+ text-decoration: none;
49
+ color: #555555;
50
+ }
51
+ }
52
+
53
+ .container
54
+ {
55
+ padding: 10px 20px;
56
+ }
57
+
58
+ .footer
59
+ {
60
+ padding: 20px;
61
+ background-color: #f5f5f5;
62
+ border-top: 1px solid #dedede;
63
+ overflow: auto;
64
+ }
65
+ }
66
+
67
+ #tinymce-templates-preview
68
+ {
69
+ border: none;
70
+ margin: 10px 0;
71
+ padding: 0;
72
+ border: 1px solid #dedede;
73
+ width: 100%;
74
+ }
75
+
76
+ #tinymce-templates-message
77
+ {
78
+ display: none;
79
+ float: left;
80
+ }
81
+
82
+ #tinymce-templates-insert
83
+ {
84
+ display: block;
85
+ float: right;
86
+ }
87
+ }
includes/mceplugins.class.php DELETED
@@ -1,46 +0,0 @@
1
- <?php
2
- /*
3
- Add TinyMCE plugis easily
4
-
5
- Parameters
6
- $plugin_url: url of editor_plugin.js
7
- $plugin_name: name of plugin
8
- */
9
- if (!class_exists('tinymcePlugins')) {
10
- class tinymcePlugins{
11
-
12
- private $name = null;
13
- private $url = null;
14
- private $inits = array();
15
-
16
- function __construct($plugin_name, $plugin_url,
17
- $button_callback = null, $inits = array())
18
- {
19
- $this->name = $plugin_name;
20
- $this->url = $plugin_url;
21
- add_filter('mce_external_plugins', array(&$this, 'external_plugins'));
22
- if ($inits) {
23
- $this->inits = $inits;
24
- add_filter('tiny_mce_before_init', array(&$this, 'before_init'));
25
- }
26
- if ($button_callback) {
27
- add_filter('mce_buttons', $button_callback);
28
- }
29
- }
30
-
31
- public function before_init($inits){
32
- foreach ($this->inits as $key => $value) {
33
- $inits[$key] = $value;
34
- }
35
- return $inits;
36
- }
37
-
38
- public function external_plugins($plugins = array())
39
- {
40
- $plugins[$this->name] = $this->url;
41
- return $plugins;
42
- }
43
- }
44
- }
45
-
46
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/tinymce-templates.js ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
2
+ var tinymceTemplates;
3
+
4
+ ( function( $ ) {
5
+ var editor,
6
+
7
+ tinymceTemplates = {
8
+
9
+ init: function()
10
+ {
11
+ $('#button-tinymce-templates').bind('click', function(e){
12
+ e.preventDefault();
13
+ tinymceTemplates.get_template_list();
14
+ tinymceTemplates.open();
15
+ });
16
+
17
+ $(window).resize(function(){
18
+ tinymceTemplates.positionTop();
19
+ });
20
+
21
+ $('.close').click(function(e){
22
+ e.preventDefault();
23
+ tinymceTemplates.close();
24
+ });
25
+
26
+ $('#tinymce-templates-backdrop').click(function(e){
27
+ e.preventDefault();
28
+ tinymceTemplates.close();
29
+ });
30
+
31
+ $('#tinymce-templates-insert').click(function(e){
32
+ e.preventDefault();
33
+ if ($(this).attr('disabled')) {
34
+ return false;
35
+ }
36
+ tinymceTemplates.insert();
37
+ tinymceTemplates.close();
38
+ });
39
+
40
+ $('#tinymce-templates-list').bind('change', function(){
41
+ tinymceTemplates.set_content();
42
+ });
43
+ },
44
+
45
+ insert: function()
46
+ {
47
+ if (tinymceTemplates.is_shortcode) {
48
+ var tags = tinymceTemplates.content.match(/{\$([a-zA-Z0-9_]+?)}/g);
49
+
50
+ var args = [];
51
+ var is_content = '';
52
+
53
+ if (tags) {
54
+ var tags = tags.filter(function (x, i, self) {
55
+ return self.indexOf(x) === i;
56
+ });
57
+
58
+ for (var i=0; i<tags.length; i++) {
59
+ var tag = tags[i].match(/[a-zA-Z0-9_]+/);
60
+ if ('content' === tag[0]) {
61
+ is_content = 'Hello World![/template]';
62
+ continue;
63
+ }
64
+ args.push(tag[0] + '=""');
65
+ }
66
+ }
67
+
68
+ if (0 < args.length) {
69
+ html = '<p>[template id="' + tinymceTemplates.template_id + '" ' + args.join(' ')+']' + is_content + '</p>';
70
+ } else {
71
+ html = '<p>[template id="' + tinymceTemplates.template_id + '"]' + is_content + '</p>';
72
+ }
73
+
74
+ wp.media.editor.insert(html);
75
+ } else {
76
+ wp.media.editor.insert(tinymceTemplates.content);
77
+ }
78
+ },
79
+
80
+ get_template_list: function()
81
+ {
82
+ var args = $.extend({}, tinymce_templates_list_args);
83
+
84
+ $.ajax({
85
+ url: tinymce_templates_list_uri,
86
+ async: true,
87
+ type: 'GET',
88
+ dataType: 'json',
89
+ data: args
90
+ }).done(function(data){
91
+ $.each(data, function(key, tpl){
92
+ var option = $('<option />');
93
+ $(option).attr('value', key);
94
+ $(option).text(tpl.title);
95
+ $('#tinymce-templates-list').append(option);
96
+ });
97
+
98
+ tinymceTemplates.set_content();
99
+ });
100
+ },
101
+
102
+ set_content: function()
103
+ {
104
+ $('#tinymce-templates-insert').attr('disabled', true);
105
+
106
+ tinymceTemplates.template_id = $('#tinymce-templates-list').val();
107
+
108
+ // I don't like reference here!!
109
+ var args = $.extend({}, tinymce_templates_list_args);
110
+ args['template_id'] = tinymceTemplates.template_id;
111
+
112
+ $.ajax({
113
+ url: tinymce_templates_list_uri,
114
+ async: true,
115
+ type: 'GET',
116
+ dataType: 'json',
117
+ data: args
118
+ }).done(function(data){
119
+ var content_css = tinyMCEPreInit.mceInit.content.content_css;
120
+ var styles = content_css.replace(/(\s+)/g, "").split(',');
121
+
122
+ var html = '<!DOCTYPE html><html><head>';
123
+ for (var i=0; i<styles.length; i++) {
124
+ var link = $('<link rel="stylesheet" type="text/css" media="all" />');
125
+ link.attr('href', styles[i]);
126
+ html += $('<div />').html(link).html(); // getting innerHTML
127
+ }
128
+ html += '</head><body class="mceContentBody">';
129
+ html += data.content;
130
+ html += '</body></html>';
131
+
132
+ var iframe = document.getElementById('tinymce-templates-preview');
133
+ var doc = iframe.contentWindow.document;
134
+ doc.open();
135
+ doc.write(html);
136
+ doc.close();
137
+
138
+ if (data.is_shortcode) {
139
+ $('#tinymce-templates-message').show();
140
+ } else {
141
+ $('#tinymce-templates-message').hide();
142
+ }
143
+
144
+ tinymceTemplates.is_shortcode = data.is_shortcode;
145
+ tinymceTemplates.content = data.content;
146
+
147
+ $('#tinymce-templates-insert').attr('disabled', false);
148
+ });
149
+ },
150
+
151
+ open: function( editorId )
152
+ {
153
+ $('#tinymce-templates-list').html('');
154
+ var iframe = document.getElementById('tinymce-templates-preview');
155
+ var doc = iframe.contentWindow.document;
156
+ doc.open();
157
+ doc.write('');
158
+ doc.close();
159
+
160
+ tinymceTemplates.positionTop();
161
+
162
+ $( document.body ).addClass( 'modal-open' );
163
+ $('#tinymce-templates-wrap').show();
164
+ $( '#tinymce-templates-backdrop' ).show();
165
+ },
166
+
167
+ close: function()
168
+ {
169
+ $(document.body ).removeClass('modal-open');
170
+ $('#tinymce-templates-wrap').hide();
171
+ $('#tinymce-templates-backdrop').hide();
172
+ $('#tinymce-templates-insert').attr('disabled', true);
173
+ },
174
+
175
+ positionTop: function()
176
+ {
177
+ var windowHeight = $(document.body).height();
178
+
179
+ $('#tinymce-templates-preview').css('height', windowHeight * 0.5);
180
+
181
+ var height = $('#tinymce-templates-wrap').height();
182
+
183
+ var top = (windowHeight / 2) - (height / 2) - ($('#wpadminbar').height() / 2);
184
+ if (top < (0 - $('#wpadminbar').height() + 8)) {
185
+ top = (0 - $('#wpadminbar').height() + 8);
186
+ } else if (top > 100) {
187
+ top = 100;
188
+ }
189
+
190
+ $('#tinymce-templates-wrap').css('top', top);
191
+ },
192
+ };
193
+
194
+ $( document ).ready( tinymceTemplates.init );
195
+
196
+ })( jQuery );
mce_plugins/4.0/plugins/template/plugin.js DELETED
@@ -1,185 +0,0 @@
1
- /**
2
- * plugin.js
3
- *
4
- * Released under LGPL License.
5
- *
6
- * License: http://www.tinymce.com/license
7
- * Contributing: http://www.tinymce.com/contributing
8
- */
9
-
10
- /*global tinymce:true */
11
-
12
- tinymce.PluginManager.add('template', function(editor) {
13
- var each = tinymce.each;
14
-
15
- function createTemplateList(callback) {
16
- return function() {
17
- var templateList = editor.settings.templates;
18
-
19
- if (typeof(templateList) == "string") {
20
- tinymce.util.XHR.send({
21
- url: templateList,
22
- success: function(text) {
23
- callback(tinymce.util.JSON.parse(text));
24
- }
25
- });
26
- } else {
27
- callback(templateList);
28
- }
29
- };
30
- }
31
-
32
- function showDialog(templateList) {
33
- var win, values = [], templateHtml, id, is_shortcode, label;
34
-
35
- if (!templateList || templateList.length === 0) {
36
- editor.windowManager.alert('No templates defined');
37
- return;
38
- }
39
-
40
- tinymce.each(templateList, function(template) {
41
- values.push({
42
- selected: !values.length,
43
- text: template.title,
44
- value: {
45
- id: template.id,
46
- url: template.url,
47
- content: template.content,
48
- is_shortcode: template.is_shortcode
49
- }
50
- });
51
- });
52
-
53
- function onSelectTemplate(e) {
54
- var value = e.control.value();
55
-
56
- function insertIframeHtml(html) {
57
- if (html.indexOf('<html>') == -1) {
58
- var contentCssLinks = '';
59
-
60
- tinymce.each(editor.contentCSS, function(url) {
61
- contentCssLinks += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '">';
62
- });
63
-
64
- html = (
65
- '<!DOCTYPE html>' +
66
- '<html>' +
67
- '<head>' +
68
- contentCssLinks +
69
- '</head>' +
70
- '<body class="mceContentBody">' +
71
- html +
72
- '</body>' +
73
- '</html>'
74
- );
75
- }
76
-
77
- var doc = win.find('iframe')[0].getEl().contentWindow.document;
78
- doc.open();
79
- doc.write(html);
80
- doc.close();
81
- }
82
-
83
- if (value.url) {
84
- tinymce.util.XHR.send({
85
- url: value.url,
86
- success: function(html) {
87
- templateHtml = html;
88
- insertIframeHtml(templateHtml);
89
- id = value.id;
90
- is_shortcode = value.is_shortcode;
91
- }
92
- });
93
- } else {
94
- templateHtml = value.content;
95
- insertIframeHtml(templateHtml);
96
- }
97
-
98
- if (value.is_shortcode) {
99
- label = "Note: The template will be inserted as shortcode.";
100
- } else {
101
- label = '\u00a0';
102
- }
103
-
104
- win.find('#is_shortcode')[0].text(label);
105
- }
106
-
107
- win = editor.windowManager.open({
108
- title: 'Insert template',
109
- layout: 'flex',
110
- direction: 'column',
111
- align: 'stretch',
112
- padding: 15,
113
- spacing: 10,
114
-
115
- items: [
116
- {type: 'form', flex: 0, padding: 0, items: [
117
- {type: 'container', label: 'Templates', items: {
118
- type: 'listbox', label: 'Templates', name: 'template', values: values, onselect: onSelectTemplate
119
- }}
120
- ]},
121
-
122
- {type: 'iframe', flex: 1, border: 1},
123
- {type: 'label', name: 'is_shortcode', label: '', text: '\u00a0'},
124
- ],
125
-
126
- onsubmit: function() {
127
- insertTemplate(false, templateHtml, id, is_shortcode);
128
- },
129
-
130
- width: editor.getParam('template_popup_width', 600),
131
- height: editor.getParam('template_popup_height', 500)
132
- });
133
-
134
- win.find('listbox')[0].fire('select');
135
- }
136
-
137
- function insertTemplate(ui, html, id, is_shortcode) {
138
- if (is_shortcode) {
139
- var tags = html.match(/{\$([a-zA-Z0-9_]+?)}/g);
140
-
141
- var args = [];
142
- var is_content = '';
143
-
144
- if (tags) {
145
- for (var i=0; i<tags.length; i++) {
146
- var tag = tags[i].match(/[a-zA-Z0-9_]+/);
147
- if ('content' === tag[0]) {
148
- is_content = 'Hello World![/template]';
149
- continue;
150
- }
151
- args.push(tag[0] + '=""');
152
- }
153
- }
154
-
155
- if (0 < args.length) {
156
- html = '<p>[template id="' + id + '" ' + args.join(' ')+']' + is_content + '</p>';
157
- } else {
158
- html = '<p>[template id="' + id + '"]' + is_content + '</p>';
159
- }
160
-
161
- editor.execCommand('mceInsertContent', false, html);
162
- editor.addVisual();
163
- } else {
164
- var el, n, dom = editor.dom, sel = editor.selection.getContent();
165
- el = dom.create('div', null, html);
166
-
167
- editor.execCommand('mceInsertContent', false, el.innerHTML);
168
- editor.addVisual();
169
- }
170
- }
171
-
172
- editor.addCommand('mceInsertTemplate', insertTemplate);
173
- editor.addCommand('createTemplateList', createTemplateList(showDialog));
174
-
175
- editor.addButton('template', {
176
- title: 'Insert template',
177
- onclick: createTemplateList(showDialog)
178
- });
179
-
180
- editor.addMenuItem('template', {
181
- text: 'Insert template',
182
- onclick: createTemplateList(showDialog),
183
- context: 'insert'
184
- });
185
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
mce_plugins/4.0/plugins/template/plugin.min.js DELETED
@@ -1 +0,0 @@
1
- tinymce.PluginManager.add("template",function(e){function t(t){return function(){var a=e.settings.templates;"string"==typeof a?tinymce.util.XHR.send({url:a,success:function(e){t(tinymce.util.JSON.parse(e))}}):t(a)}}function a(t){function a(t){function a(t){if(-1==t.indexOf("<html>")){var a="";tinymce.each(e.contentCSS,function(t){a+='<link type="text/css" rel="stylesheet" href="'+e.documentBaseURI.toAbsolute(t)+'">'}),t="<!DOCTYPE html><html><head>"+a+"</head><body>"+t+"</body></html>"}t=r(t,"template_preview_replace_values");var l=n.find("iframe")[0].getEl().contentWindow.document;l.open(),l.write(t),l.close()}var c=t.control.value();c.url?tinymce.util.XHR.send({url:c.url,success:function(e){l=e,a(l)}}):(l=c.content,a(l)),n.find("#description")[0].text(t.control.value().description)}var n,l,i=[];return t&&0!==t.length?(tinymce.each(t,function(e){i.push({selected:!i.length,text:e.title,value:{url:e.url,content:e.content,description:e.description}})}),n=e.windowManager.open({title:"Insert template",layout:"flex",direction:"column",align:"stretch",padding:15,spacing:10,items:[{type:"form",flex:0,padding:0,items:[{type:"container",label:"Templates",items:{type:"listbox",label:"Templates",name:"template",values:i,onselect:a}}]},{type:"label",name:"description",label:"Description",text:" "},{type:"iframe",flex:1,border:1}],onsubmit:function(){c(!1,l)},width:e.getParam("template_popup_width",600),height:e.getParam("template_popup_height",500)}),void n.find("listbox")[0].fire("select")):void e.windowManager.alert("No templates defined")}function n(t,a){function n(e,t){if(e=""+e,e.length<t)for(var a=0;a<t-e.length;a++)e="0"+e;return e}var l="Sun Mon Tue Wed Thu Fri Sat Sun".split(" "),r="Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" "),c="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),i="January February March April May June July August September October November December".split(" ");return a=a||new Date,t=t.replace("%D","%m/%d/%Y"),t=t.replace("%r","%I:%M:%S %p"),t=t.replace("%Y",""+a.getFullYear()),t=t.replace("%y",""+a.getYear()),t=t.replace("%m",n(a.getMonth()+1,2)),t=t.replace("%d",n(a.getDate(),2)),t=t.replace("%H",""+n(a.getHours(),2)),t=t.replace("%M",""+n(a.getMinutes(),2)),t=t.replace("%S",""+n(a.getSeconds(),2)),t=t.replace("%I",""+((a.getHours()+11)%12+1)),t=t.replace("%p",""+(a.getHours()<12?"AM":"PM")),t=t.replace("%B",""+e.translate(i[a.getMonth()])),t=t.replace("%b",""+e.translate(c[a.getMonth()])),t=t.replace("%A",""+e.translate(r[a.getDay()])),t=t.replace("%a",""+e.translate(l[a.getDay()])),t=t.replace("%%","%")}function l(t){var a=e.dom,n=e.getParam("template_replace_values");i(a.select("*",t),function(e){i(n,function(t,l){a.hasClass(e,l)&&"function"==typeof n[l]&&n[l](e)})})}function r(t,a){return i(e.getParam(a),function(e,a){"function"!=typeof e&&(t=t.replace(new RegExp("\\{\\$"+a+"\\}","g"),e))}),t}function c(t,a){function c(e,t){return new RegExp("\\b"+t+"\\b","g").test(e.className)}var o,s,p=e.dom,m=e.selection.getContent();a=r(a,"template_replace_values"),o=p.create("div",null,a),s=p.select(".mceTmpl",o),s&&s.length>0&&(o=p.create("div",null),o.appendChild(s[0].cloneNode(!0))),i(p.select("*",o),function(t){c(t,e.getParam("template_cdate_classes","cdate").replace(/\s+/g,"|"))&&(t.innerHTML=n(e.getParam("template_cdate_format",e.getLang("template.cdate_format")))),c(t,e.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(t.innerHTML=n(e.getParam("template_mdate_format",e.getLang("template.mdate_format")))),c(t,e.getParam("template_selected_content_classes","selcontent").replace(/\s+/g,"|"))&&(t.innerHTML=m)}),l(o),e.execCommand("mceInsertContent",!1,o.innerHTML),e.addVisual()}var i=tinymce.each;e.addCommand("mceInsertTemplate",c),e.addButton("template",{title:"Insert template",onclick:t(a)}),e.addMenuItem("template",{text:"Insert template",onclick:t(a),context:"insert"}),e.on("PreProcess",function(t){var a=e.dom;i(a.select("div",t.node),function(t){a.hasClass(t,"mceTmpl")&&(i(a.select("*",t),function(t){a.hasClass(t,e.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(t.innerHTML=n(e.getParam("template_mdate_format",e.getLang("template.mdate_format"))))}),l(t))})})});
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: miyauchi
3
  Tags: tinymce, Visual Editor, template
4
  Requires at least: 4.0
5
  Tested up to: 4.1
6
- Stable tag: 4.2.0
7
 
8
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
9
 
@@ -55,6 +55,10 @@ You can send your own language pack to me.
55
 
56
  == Changelog ==
57
 
 
 
 
 
58
  = 4.0.0 =
59
 
60
  * Remove sharing function.
3
  Tags: tinymce, Visual Editor, template
4
  Requires at least: 4.0
5
  Tested up to: 4.1
6
+ Stable tag: 4.3.1
7
 
8
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
9
 
55
 
56
  == Changelog ==
57
 
58
+ = 4.3.1 =
59
+
60
+ * Bug fix on quick tags view.
61
+
62
  = 4.0.0 =
63
 
64
  * Remove sharing function.
tinymce-templates.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: TinyMCE Templates
4
  Plugin URI: http://miya0001.github.io/tinymce-templates/
5
  Description: TinyMCE Templates plugin will enable to use HTML template on WordPress Visual Editor.
6
  Author: Takayuki Miyauchi
7
- Version: 4.2.0
8
  Author URI: http://miya0001.github.io/tinymce-templates/
9
  Domain Path: /languages
10
  Text Domain: tinymce_templates
@@ -125,23 +125,47 @@ class TinyMCE_Templates {
125
 
126
  add_action( 'admin_head', array( $this, 'admin_head' ) );
127
  add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer' ) );
128
- add_action( 'wp_ajax_tinymce_templates', array( $this, 'wp_ajax' ) );
 
129
  add_action( 'post_submitbox_start', array( $this, 'post_submitbox_start' ) );
130
  add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ) );
131
  add_action( 'save_post', array( $this, 'save_post' ) );
132
  add_action( 'media_buttons', array( $this, 'media_buttons' ), 11 );
 
133
 
134
  add_shortcode( 'template', array( $this, 'template_shortcode' ) );
135
  }
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  public function media_buttons( $editor_id = 'content' )
138
  {
139
- printf(
140
- '<a id="button-tinymce-templates" class="button" href="#" data-editor="%s" title="%s" onclick="tinymce.execCommand(\'createTemplateList\'); return false;">%s</a>',
141
- esc_attr( $editor_id ),
142
- esc_attr( __( 'Insert Template', 'tinymce_templates' ) ),
143
- esc_html( __( 'Insert Template', 'tinymce_templates' ) )
144
- );
 
 
145
  }
146
 
147
  /**
@@ -152,6 +176,8 @@ class TinyMCE_Templates {
152
  */
153
  public function template_shortcode( $p, $content )
154
  {
 
 
155
  if ( isset( $p['id'] ) && intval( $p['id'] ) ) {
156
  $args = array(
157
  'ID' => $p['id'],
@@ -162,9 +188,11 @@ class TinyMCE_Templates {
162
  $post = get_post( $p['id'] );
163
 
164
  if ( $post && get_post_meta( $p['id'], 'insert_as_shortcode', true ) ) {
165
- return apply_filters( 'tinymce_templates_content', $post->post_content, $p, $content );
166
  }
167
  }
 
 
168
  }
169
 
170
  /**
@@ -258,29 +286,29 @@ class TinyMCE_Templates {
258
  */
259
  public function admin_head()
260
  {
261
- /**
262
- * Load and setup tinymce plugin.
263
- */
264
- $url = admin_url( 'admin-ajax.php' );
265
- $nonce = wp_create_nonce( 'tinymce_templates' );
266
-
267
- $args = array(
268
- 'action' => 'tinymce_templates',
269
- 'nonce' => $nonce,
270
- );
271
-
272
- $url = add_query_arg( $args, $url );
273
-
274
- $inits['templates'] = $url;
275
-
276
- require_once( dirname( __FILE__ ) . '/includes/mceplugins.class.php' );
277
-
278
- new tinymcePlugins(
279
- 'template',
280
- $this->base_url.'/mce_plugins/4.0/plugins/template/plugin.js',
281
- false,
282
- $inits
283
- );
284
 
285
  /**
286
  * Hide some stuff in the templates editor panel.
@@ -459,25 +487,61 @@ class TinyMCE_Templates {
459
  */
460
  public function admin_footer()
461
  {
462
- if ( get_post_type() === $this->post_type ) {
463
- if ( isset( $_GET['origin'] ) && intval( $_GET['origin'] ) ) {
464
- $origin = get_post( intval( $_GET['origin'] ) );
465
- if ( $origin ) {
466
- $template = array(
467
- 'post_title' => $origin->post_title,
468
- 'post_content' => wpautop( $origin->post_content ),
469
- );
470
- $template = json_encode( $template );
471
- echo <<<EOL
472
- <script type="text/javascript">
473
- var origin = {$template};
474
- jQuery( '#title').val(origin.post_title );
475
- jQuery( '#content').val(origin.post_content );
476
- </script>
477
- EOL;
 
 
478
  }
479
  }
480
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  }
482
 
483
  /**
@@ -486,7 +550,7 @@ EOL;
486
  * @param none
487
  * @return none
488
  */
489
- public function wp_ajax()
490
  {
491
  nocache_headers();
492
 
@@ -506,43 +570,38 @@ EOL;
506
 
507
  $posts = get_posts( $p );
508
 
509
- $url = admin_url( 'admin-ajax.php' );
510
- $nonce = wp_create_nonce( 'tinymce_templates' );
511
-
512
  $arr = array();
513
 
514
  foreach ( $posts as $p ) {
515
  $ID = intval( $p->ID );
516
  $name = esc_html( apply_filters( 'tinymce_template_title', $p->post_title ) );
517
  $desc = esc_html( apply_filters( 'tinymce_template_excerpt', $p->post_excerpt ) );
518
- $args = array(
519
- 'action' => 'tinymce_templates',
520
- 'template_id' => $ID,
521
- 'nonce' => $nonce,
522
- );
523
- $url = add_query_arg( $args, $url );
524
  $arr[ $ID ] = array(
525
- 'id' => $ID,
526
  'title' => $name,
527
- 'url' => $url,
528
  'is_shortcode' => get_post_meta( $ID, 'insert_as_shortcode', true ),
529
- 'content' => $p->post_content,
530
  );
531
  }
532
 
533
  $arr = apply_filters( 'tinymce_templates_post_objects', $arr );
534
 
535
- if ( isset( $_GET['template_id'] ) && intval( $_GET['template_id'] ) ) {
536
- $p = $arr[ $_GET['template_id'] ];
537
- echo apply_filters(
538
- 'tinymce_templates',
539
- $p['content'],
540
- $p['content']
541
- );
 
 
 
 
 
 
542
  exit;
543
  }
544
 
545
- echo json_encode( array_values( $arr ) );
546
  exit;
547
  }
548
 
4
  Plugin URI: http://miya0001.github.io/tinymce-templates/
5
  Description: TinyMCE Templates plugin will enable to use HTML template on WordPress Visual Editor.
6
  Author: Takayuki Miyauchi
7
+ Version: 4.3.1
8
  Author URI: http://miya0001.github.io/tinymce-templates/
9
  Domain Path: /languages
10
  Text Domain: tinymce_templates
125
 
126
  add_action( 'admin_head', array( $this, 'admin_head' ) );
127
  add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer' ) );
128
+ add_action( 'admin_footer-post.php', array( $this, 'admin_footer' ) );
129
+ add_action( 'wp_ajax_tinymce_templates', array( $this, 'wp_ajax_tinymce_templates' ) );
130
  add_action( 'post_submitbox_start', array( $this, 'post_submitbox_start' ) );
131
  add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ) );
132
  add_action( 'save_post', array( $this, 'save_post' ) );
133
  add_action( 'media_buttons', array( $this, 'media_buttons' ), 11 );
134
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
135
 
136
  add_shortcode( 'template', array( $this, 'template_shortcode' ) );
137
  }
138
 
139
+ public function admin_enqueue_scripts( $hook_suffix )
140
+ {
141
+ if ( 'post-new.php' === $hook_suffix || 'post.php' === $hook_suffix ) {
142
+ wp_enqueue_script(
143
+ 'tinymce-templates',
144
+ plugins_url( 'js/tinymce-templates.js', __FILE__ ),
145
+ array( 'jquery' ),
146
+ filemtime( dirname( __FILE__ ) . '/js/tinymce-templates.js' ),
147
+ true
148
+ );
149
+
150
+ wp_enqueue_style(
151
+ 'tinymce-templates',
152
+ plugins_url( 'css/tinymce-templates.css', __FILE__ ),
153
+ array(),
154
+ filemtime( dirname( __FILE__ ) . '/css/tinymce-templates.css' )
155
+ );
156
+ }
157
+ }
158
+
159
  public function media_buttons( $editor_id = 'content' )
160
  {
161
+ if ( 'content' === $editor_id ) {
162
+ printf(
163
+ '<a id="button-tinymce-templates" class="button" href="#" data-editor="%s" title="%s">%s</a>',
164
+ esc_attr( $editor_id ),
165
+ esc_attr( __( 'Insert Template', 'tinymce_templates' ) ),
166
+ esc_html( __( 'Insert Template', 'tinymce_templates' ) )
167
+ );
168
+ }
169
  }
170
 
171
  /**
176
  */
177
  public function template_shortcode( $p, $content )
178
  {
179
+ $post_content = '';
180
+
181
  if ( isset( $p['id'] ) && intval( $p['id'] ) ) {
182
  $args = array(
183
  'ID' => $p['id'],
188
  $post = get_post( $p['id'] );
189
 
190
  if ( $post && get_post_meta( $p['id'], 'insert_as_shortcode', true ) ) {
191
+ $post_content = $post->post_content;
192
  }
193
  }
194
+
195
+ return apply_filters( 'tinymce_templates_content', $post_content, $p, $content );
196
  }
197
 
198
  /**
286
  */
287
  public function admin_head()
288
  {
289
+ // /**
290
+ // * Load and setup tinymce plugin.
291
+ // */
292
+ // $url = admin_url( 'admin-ajax.php' );
293
+ // $nonce = wp_create_nonce( 'tinymce_templates' );
294
+ //
295
+ // $args = array(
296
+ // 'action' => 'tinymce_templates',
297
+ // 'nonce' => $nonce,
298
+ // );
299
+ //
300
+ // $url = add_query_arg( $args, $url );
301
+ //
302
+ // $inits['templates'] = $url;
303
+ //
304
+ // require_once( dirname( __FILE__ ) . '/includes/mceplugins.class.php' );
305
+ //
306
+ // new tinymcePlugins(
307
+ // 'template',
308
+ // $this->base_url.'/mce_plugins/4.0/plugins/template/plugin.js',
309
+ // false,
310
+ // $inits
311
+ // );
312
 
313
  /**
314
  * Hide some stuff in the templates editor panel.
487
  */
488
  public function admin_footer()
489
  {
490
+ global $hook_suffix;
491
+ if ( 'post-new.php' === $hook_suffix ) {
492
+ if ( get_post_type() === $this->post_type ) {
493
+ if ( isset( $_GET['origin'] ) && intval( $_GET['origin'] ) ) {
494
+ $origin = get_post( intval( $_GET['origin'] ) );
495
+ if ( $origin ) {
496
+ $template = array(
497
+ 'post_title' => $origin->post_title,
498
+ 'post_content' => wpautop( $origin->post_content ),
499
+ );
500
+ ?>
501
+ <script type="text/javascript">
502
+ var origin = <?php echo json_encode( $template ); ?>;
503
+ jQuery( '#title').val(origin.post_title );
504
+ jQuery( '#content').val(origin.post_content );
505
+ </script>
506
+ <?php
507
+ }
508
  }
509
  }
510
  }
511
+
512
+ ?>
513
+ <div id="tinymce-templates-backdrop" style="desplay: none;"></div>
514
+ <div id="tinymce-templates-wrap" class="wp-core-ui search-panel-visible" style="desplay: none;">
515
+ <div class="modal">
516
+ <div class="header">
517
+ <h1><span class="dashicons dashicons-edit"></span> <?php _e( 'Insert Template', 'tinymce_templates' ); ?></h1>
518
+ <a href="#" class="close"><span class="dashicons dashicons-no-alt"></span></a>
519
+ </div>
520
+ <div class="container">
521
+ <select id="tinymce-templates-list"></select>
522
+ <iframe id="tinymce-templates-preview"></iframe>
523
+ </div>
524
+ <div class="footer">
525
+ <div id="tinymce-templates-message"><?php _e( 'Note: The template will be inserted as shortcode.', 'tinymce_templates' ); ?></div>
526
+ <a href="#" id="tinymce-templates-insert" class="button button-primary button-large template-button-insert" disabled><?php _e( 'Insert Template', 'tinymce_templates' ); ?></a>
527
+ </div>
528
+ </div>
529
+ </div>
530
+ <?php
531
+
532
+ $url = admin_url( 'admin-ajax.php' );
533
+ $nonce = wp_create_nonce( 'tinymce_templates' );
534
+
535
+ $args = array(
536
+ 'action' => 'tinymce_templates',
537
+ 'nonce' => $nonce,
538
+ );
539
+ ?>
540
+ <script type="text/javascript">
541
+ var tinymce_templates_list_uri = '<?php echo $url; ?>';
542
+ var tinymce_templates_list_args = <?php echo json_encode($args); ?>;
543
+ </script>
544
+ <?php
545
  }
546
 
547
  /**
550
  * @param none
551
  * @return none
552
  */
553
+ public function wp_ajax_tinymce_templates()
554
  {
555
  nocache_headers();
556
 
570
 
571
  $posts = get_posts( $p );
572
 
 
 
 
573
  $arr = array();
574
 
575
  foreach ( $posts as $p ) {
576
  $ID = intval( $p->ID );
577
  $name = esc_html( apply_filters( 'tinymce_template_title', $p->post_title ) );
578
  $desc = esc_html( apply_filters( 'tinymce_template_excerpt', $p->post_excerpt ) );
 
 
 
 
 
 
579
  $arr[ $ID ] = array(
 
580
  'title' => $name,
 
581
  'is_shortcode' => get_post_meta( $ID, 'insert_as_shortcode', true ),
582
+ 'content' => wpautop( $p->post_content ),
583
  );
584
  }
585
 
586
  $arr = apply_filters( 'tinymce_templates_post_objects', $arr );
587
 
588
+ if ( isset( $_GET['template_id'] ) && $_GET['template_id'] ) {
589
+ if ( isset( $arr[ $_GET['template_id'] ] ) && $arr[ $_GET['template_id'] ] ) {
590
+ $p = $arr[ $_GET['template_id'] ];
591
+ $content = apply_filters(
592
+ 'tinymce_templates',
593
+ $p['content'],
594
+ $p['content']
595
+ );
596
+ echo json_encode( array(
597
+ 'content' => $content,
598
+ 'is_shortcode' => $p['is_shortcode']
599
+ ) );
600
+ }
601
  exit;
602
  }
603
 
604
+ echo json_encode( $arr );
605
  exit;
606
  }
607