PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.3.0
Gallery : FooGallery v3.3.0
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / js / admin-tinymce.js
foogallery / js Last commit date
admin-foogallery-attachment-autosave.js 1 week ago admin-foogallery-divi.js 1 week ago admin-foogallery-edit.js 1 week ago admin-foogallery-editor.js 1 week ago admin-foogallery-elementor.js 1 week ago admin-page-foogallery-extensions-modal.js 1 week ago admin-page-foogallery-extensions.js 1 week ago admin-page-foogallery-settings.js 1 week ago admin-tinymce.js 1 week ago admin-uploader.js 1 week ago foogallery-command-palette.js 1 week ago foogallery.admin.datasources.js 1 week ago foogallery.admin.min.js 1 week ago foogallery.admin.template.js 1 week ago
admin-tinymce.js
161 lines
1 (function() {
2 tinymce.PluginManager.add('foogallery', function( editor, url ) {
3
4 function getParentFooGallery( node ) {
5 while ( node && node.nodeName !== 'BODY' ) {
6 if ( isFooGallery( node ) ) {
7 return node;
8 }
9
10 node = node.parentNode;
11 }
12 }
13
14 function isFooGallery( node ) {
15 return node && /foogallery-tinymce-view/.test( node.className );
16 }
17
18 function unselectFooGallery( dom ) {
19 dom.removeClass(dom.select('div.foogallery-tinymce-selected'), 'foogallery-tinymce-selected');
20 }
21
22 editor.on( 'BeforeSetContent', function( event ) {
23 if ( ! event.content ) {
24 return;
25 }
26
27 var shortcode_tag = window.FOOGALLERY_SHORTCODE || 'foogallery',
28 regexp = new RegExp('\\[' + shortcode_tag + ' ([^\\]]*)\\]', 'g');
29
30 event.content = event.content.replace( regexp, function( match ) {
31
32 var data = window.encodeURIComponent( match ),
33 idRegex = / id=\"(.*?)\"/ig,
34 idMatch = idRegex.exec(match),
35 id = idMatch ? idMatch[1] : 0;
36
37 return '<div class="foogallery-tinymce-view mceNonEditable" data-foogallery="' + data + '" contenteditable="false" data-mce-resize="false" data-mce-placeholder="1" data-foogallery-id="' + id + '">' +
38 ' <div class="foogallery-tinymce-toolbar">' +
39 ' <a class="dashicons dashicons-edit foogallery-tinymce-toolbar-edit" href="post.php?post=' + id + '&action=edit" target="_blank">&nbsp;</a>' +
40 ' <div class="dashicons dashicons-no-alt foogallery-tinymce-toolbar-delete">&nbsp;</div>' +
41 ' </div>' +
42 ' <div class="foogallery-pile">' +
43 ' <div class="foogallery-pile-inner">' +
44 ' <div class="foogallery-pile-inner-thumb"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAIAAACzY+a1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABKBJREFUeNrs3I1P2loYx3EoRaXKiyVXF7Ilg+3//4e2FBDNhPbSYgrIq3vsuZcQJwqywDnw/cUYJG5pzqfPOc9pi+l2t5ciJsdiCCAkEBIIISQQEggJhBASCAmEBEIICYQEQgIhhARCAiGBEEICIYGQQAghgZBASCCEkEBIICQQQkggJBASCCEkEBIICYQQEggJhARCCAmEBEICIYQEQgIhWS+2tkeWTqLP8TwlgXDtycGyZrNZP45Tmig+PeUc5+TkRI4KwveTyWSiMLy7uxsMBpoUotRfLpe7/vTJdV05JK3K0daw/sIwrHvefD4XS30ObDQayVFNJpNKpaJVLepYhff39/PZzMpkRFGrc0tOqftfv4rFouM4+hybrVsJxnE8HAxktGSyKpVKMnftfbDkqP6VBIFMoVJ/UoishW9lnkRGTQivrq8LhYIOhPI98P30/4FwgyZCib46prvs8rWa0k0ifLUgpAj6/b7MZtIinp6eKma29mZEuglpVjvt9nA4FMKzs7N8Pi+TrVges6JtkF8QBM1m87lZTZrD8Xjs+363263VasVS6WgVzbhGKma9Xu+m2ZQFUPBUQyHfM8nG4/b2VhpF3boMCF9G5s9XnURX5tWw292UUC2rEO4ogjedTleNuLwv0+lG/6H8kyiKDqN2DSBUG+o3CD+yrPr+zx8/GvW6NLSmKxpAKKN8kmTVLlD9wvp+Mie3Wi2ZSKUQ655nuqIxa6Fzfr6KUFRka7GR36IbUpfUjVY0g1CGuFKpFIvFF7cI5P3pZOK67jrXnV/4Le81jVY0hlDGt1qrlS4vZVFUV91UMyL19/nLl3evtL3qdxiKxmztZXxt265Wq9dXV2EUDQcDKUrZ0av6e5vwDb9lxZTnyVmi2x3dwyFMJdeapQfJFwrytbzf+HD9HYaiYU+wLe5dLPJX/IyeUY1/CNFKsr2fuYpmE8qId5P8+ZTNB/wMVbSN9ovCsFGvP7+2LGlWF+vih/1erItfq9VVJU4V/h0/z/PUj/JCflS1uKXfcn3Hcax/IVpG+6m5TjWQSjGbzba39lusskyku/BTbyrFRqPx8PAQBMH2flyd2anfQlHWwk6nc1R+KeOenVnlt1A8wnv31sH4HW3MqMLFBy3wM7IKxWw8Hreazfl8jp+pE+nzvYgja1IOf2tPIKSd2cdcuuO18N07yRCuGxnHbDb77fv33Q9oLpfTvwc2owplEPP5/F7OHgi33Q4uT2v7PYcg3OzEV6+jKLq4uMgkH9re75k0Ho0gXNdPzBzHeXx8lIHrtNv9OLYymdR+24p0etDvLz5azAe13yG0bdstl1s3N/JCBiuOY32m9Ol0Wi6Xz1c/V86+8L81758kMkz6/HkXOSrxu3Tdr9Wqbo8optvdnob9ZzqZuzq+L4vQ3ieup+Q+ieu6hUJB/SkOvYZLQ8I/21ENWy3WwrXmrhQxcS0kEEJIICQQEgghJBASCAmEEBIICYQEQggJhARCAiGEBEICIYEQQgIhgZBACCGBkEBIIISQQEggJBBCSCAkEBIIISQQEggJhBASCAmEBEIICYQEQgIhhETX/BZgAHryyaJUyijaAAAAAElFTkSuQmCC" /></div>' +
45 ' </div>' +
46 ' </div>' +
47 ' <div class="foogallery-tinymce-title">&nbsp;</div>' +
48 ' <div class="foogallery-tinymce-count">' + match + '</div>' +
49 '</div>';
50 });
51 });
52
53 editor.on( 'LoadContent', function( event ) {
54 if ( ! event.content ) {
55 return;
56 }
57
58 var dom = editor.dom;
59
60 // Replace the foogallery node with the shortcode
61 tinymce.each( dom.select( 'div[data-foogallery]', event.node ), function( node ) {
62
63 if ( !dom.hasClass(node, 'foogallery-tinymce-databound') ) {
64 dom.addClass(node, 'foogallery-tinymce-databound');
65
66 //we need to post to our ajax handler and get some gallery info
67 var id = dom.getAttrib( node, 'data-foogallery-id'),
68 nonce = jQuery('#foogallery-timnymce-action-nonce').val(),
69 data = 'action=foogallery_tinymce_load_info&foogallery_id=' + id + '&nonce=' + nonce;
70
71 jQuery.ajax({
72 type: "POST",
73 url: ajaxurl,
74 data: data,
75 dataType: 'JSON',
76 success: function(response) {
77 var titleDiv = dom.select( '.foogallery-tinymce-title', node),
78 countDiv = dom.select( '.foogallery-tinymce-count', node),
79 galleryImg = dom.select( '.foogallery-pile-inner-thumb', node ),
80 payload = response && response.success ? response.data : null;
81
82 if (!payload) {
83 return;
84 }
85
86 if (titleDiv && titleDiv.length) {
87 titleDiv[0].textContent = payload.name;
88 }
89 if (countDiv && countDiv.length) {
90 countDiv[0].textContent = payload.count;
91 }
92 if (galleryImg && galleryImg.length) {
93 jQuery(galleryImg[0]).replaceWith('<img src="' + payload.src + '" />');
94 }
95 }
96 });
97 }
98 });
99 });
100
101 editor.on( 'PreProcess', function( event ) {
102 var dom = editor.dom;
103
104 // Replace the foogallery node with the shortcode
105 tinymce.each( dom.select( 'div[data-foogallery]', event.node ), function( node ) {
106 // Empty the wrap node
107 if ( 'textContent' in node ) {
108 node.textContent = '\u00a0';
109 } else {
110 node.innerText = '\u00a0';
111 }
112 });
113 });
114
115 editor.on( 'PostProcess', function( event ) {
116 if ( event.content ) {
117 event.content = event.content.replace( /<div [^>]*?data-foogallery="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) {
118 if ( shortcode ) {
119 return '<p>' + window.decodeURIComponent( shortcode ) + '</p>';
120 }
121 return ''; // If error, remove the foogallery view
122 });
123 }
124 });
125
126 editor.on( 'mouseup', function( event ) {
127 var dom = editor.dom,
128 node = event.target,
129 fg = getParentFooGallery( node );
130
131 // Don't trigger on right-click
132 if ( event.button !== 2 ) {
133
134
135
136 if (fg) {
137 //we have clicked somewhere in the foogallery element
138
139 if (node.nodeName === 'A' && dom.hasClass(node, 'foogallery-tinymce-toolbar-edit')) {
140 //alert('EDIT : ' + dom.getAttrib( fg, 'data-foogallery-id' ))
141 var win = window.open(node.href, '_blank');
142 win.focus();
143 } else if (node.nodeName === 'DIV' && dom.hasClass(node, 'foogallery-tinymce-toolbar-delete')) {
144 //alert('DELETE : ' + dom.getAttrib( fg, 'data-foogallery-id' ))
145 dom.remove(fg);
146 } else {
147
148 if (!dom.hasClass(fg, 'foogallery-tinymce-selected')) {
149 unselectFooGallery(dom);
150 dom.addClass(fg, 'foogallery-tinymce-selected');
151 }
152
153 }
154 } else {
155 unselectFooGallery(dom);
156 }
157 }
158 });
159 });
160 })();
161