admin-foogallery-attachment-autosave.js
8 months ago
admin-foogallery-edit.js
8 months ago
admin-foogallery-editor.js
8 months ago
admin-foogallery-elementor.js
8 months ago
admin-page-foogallery-extensions-modal.js
8 months ago
admin-page-foogallery-extensions.js
8 months ago
admin-page-foogallery-settings.js
8 months ago
admin-tinymce.js
8 months ago
admin-uploader.js
8 months ago
foogallery.admin.datasources.js
8 months ago
foogallery.admin.min.js
8 months ago
foogallery.admin.template.js
8 months ago
admin-tinymce.js
155 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"> </a>' + |
| 40 | ' <div class="dashicons dashicons-no-alt foogallery-tinymce-toolbar-delete"> </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"> </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(data) { |
| 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 | |
| 81 | if (titleDiv && titleDiv.length) { |
| 82 | titleDiv[0].textContent = data.name; |
| 83 | } |
| 84 | if (countDiv && countDiv.length) { |
| 85 | countDiv[0].textContent = data.count; |
| 86 | } |
| 87 | if (galleryImg && galleryImg.length) { |
| 88 | jQuery(galleryImg[0]).replaceWith('<img src="' + data.src + '" />'); |
| 89 | } |
| 90 | } |
| 91 | }); |
| 92 | } |
| 93 | }); |
| 94 | }); |
| 95 | |
| 96 | editor.on( 'PreProcess', function( event ) { |
| 97 | var dom = editor.dom; |
| 98 | |
| 99 | // Replace the foogallery node with the shortcode |
| 100 | tinymce.each( dom.select( 'div[data-foogallery]', event.node ), function( node ) { |
| 101 | // Empty the wrap node |
| 102 | if ( 'textContent' in node ) { |
| 103 | node.textContent = '\u00a0'; |
| 104 | } else { |
| 105 | node.innerText = '\u00a0'; |
| 106 | } |
| 107 | }); |
| 108 | }); |
| 109 | |
| 110 | editor.on( 'PostProcess', function( event ) { |
| 111 | if ( event.content ) { |
| 112 | event.content = event.content.replace( /<div [^>]*?data-foogallery="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) { |
| 113 | if ( shortcode ) { |
| 114 | return '<p>' + window.decodeURIComponent( shortcode ) + '</p>'; |
| 115 | } |
| 116 | return ''; // If error, remove the foogallery view |
| 117 | }); |
| 118 | } |
| 119 | }); |
| 120 | |
| 121 | editor.on( 'mouseup', function( event ) { |
| 122 | var dom = editor.dom, |
| 123 | node = event.target, |
| 124 | fg = getParentFooGallery( node ); |
| 125 | |
| 126 | // Don't trigger on right-click |
| 127 | if ( event.button !== 2 ) { |
| 128 | |
| 129 | |
| 130 | |
| 131 | if (fg) { |
| 132 | //we have clicked somewhere in the foogallery element |
| 133 | |
| 134 | if (node.nodeName === 'A' && dom.hasClass(node, 'foogallery-tinymce-toolbar-edit')) { |
| 135 | //alert('EDIT : ' + dom.getAttrib( fg, 'data-foogallery-id' )) |
| 136 | var win = window.open(node.href, '_blank'); |
| 137 | win.focus(); |
| 138 | } else if (node.nodeName === 'DIV' && dom.hasClass(node, 'foogallery-tinymce-toolbar-delete')) { |
| 139 | //alert('DELETE : ' + dom.getAttrib( fg, 'data-foogallery-id' )) |
| 140 | dom.remove(fg); |
| 141 | } else { |
| 142 | |
| 143 | if (!dom.hasClass(fg, 'foogallery-tinymce-selected')) { |
| 144 | unselectFooGallery(dom); |
| 145 | dom.addClass(fg, 'foogallery-tinymce-selected'); |
| 146 | } |
| 147 | |
| 148 | } |
| 149 | } else { |
| 150 | unselectFooGallery(dom); |
| 151 | } |
| 152 | } |
| 153 | }); |
| 154 | }); |
| 155 | })(); |