PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.44
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.44
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / include / scripts / admin / block.js

block.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.44, at include/scripts/admin/block.js

150 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * block.js - Contains all Gutenberg functionality required by Photonic
3 */
4 var photonicBlockProperties;
5 jQuery(document).ready(function($) {
6 (function(wp) {
7 var el = wp.element.createElement;
8 var __ = wp.i18n.__;
9 var components = wp.components;
10 var iconEl;
11 iconEl = el('svg', {width: 23, height: 24, viewBox: "0 0 24 24"},
12 el('g', {transform: "scale(0.046785)"},
13 el('circle', {cx: "256", cy: "192", r: "128", fill: "#0085ba"}),
14 el('rect', {width: "64", height: "256", x: "128", y: "192", fill: "#0085ba"}),
15 el('circle', {cx: "256", cy: "192", r: "64", fill: "white"}),
16 el('rect', {width: "16", height: "128", x: "192", y: "192", fill: "white"})
17 )
18 );
19
20 var tag = Photonic_Gutenberg_JS.shortcode.toLowerCase() === 'gallery' ? 'gallery__photonic_random_314159' : Photonic_Gutenberg_JS.shortcode;
21 wp.blocks.registerBlockType( 'photonic/gallery', {
22 title: __('Photonic Gallery', 'photonic'),
23 category: 'widgets',
24 keywords: ['flickr', 'smugmug', 'google'],
25 icon: iconEl,
26 supports: {
27 html: false,
28 align: ['wide', 'full']
29 },
30
31 transforms: {
32 from: [
33 {
34 type: 'shortcode',
35 tag: tag,
36 attributes: {
37 shortcode: {
38 type: 'string',
39 shortcode: function(named) {
40 return JSON.stringify(named.named);
41 }
42 }
43 }
44 },
45 // Works for WP >= 5.4, which is the current release. Will not work for older versions, so this will be uncommented
46 // once WP 5.6 is out. Photonic is compatible with WP upto 2 versions old, and WP 4.9.
47 /*
48 {
49 type: 'shortcode',
50 tag: 'gallery',
51 isMatch: function(attr) {
52 var layouts = ['square', 'circle', 'random', 'mosaic', 'masonry', 'strip-above', 'strip-below', 'strip-right', 'no-strip'];
53 var providers = ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram'];
54 return (attr.named.style !== undefined && layouts.indexOf(attr.named.style) >= 0 && attr.named.type === undefined) ||
55 (attr.named.type !== undefined && providers.indexOf(attr.named.type) >= 0 && attr.named.layout !== undefined && layouts.indexOf(attr.named.layout) >= 0);
56 },
57 attributes: {
58 shortcode: {
59 type: 'string',
60 shortcode: function(named) {
61 return JSON.stringify(named.named);
62 }
63 }
64 }
65 },
66 */
67 {
68 type: 'block',
69 blocks: ['core/gallery'],
70 transform: function(attributes) {
71 var images = attributes.images;
72 var ids = '';
73 $(images).each(function(idx, val) {
74 ids += val.id + ',';
75 });
76 if (ids.length > 0) {
77 ids = ids.slice(0, -1);
78 }
79 var sc = {
80 type: 'wp',
81 ids: ids
82 };
83 return wp.blocks.createBlock('photonic/gallery', {
84 shortcode: JSON.stringify(sc)
85 });
86 }
87 }
88 ]
89 },
90
91 attributes: {
92 shortcode: {
93 type: 'string'
94 }
95 },
96
97 /**
98 * Called when Gutenberg initially loads the block.
99 */
100 edit: function( props ) {
101 var markup = [], iconClass = '';
102 var shortcode = props.attributes.shortcode || '{}';
103 shortcode = JSON.parse(shortcode);
104
105 var providers = {
106 'wp': 'WordPress',
107 'flickr': 'Flickr',
108 'smugmug': 'SmugMug',
109 'google': 'Google Photos',
110 'picasa': 'Picasa',
111 'zenfolio': 'Zenfolio',
112 'instagram': 'Instagram'
113 };
114 var source;
115
116 if (!$.isEmptyObject(shortcode) && (shortcode.type === undefined || shortcode.type === 'default')) {
117 iconClass = 'photonic-wp';
118 source = 'wp';
119 }
120 else if (shortcode.type !== undefined && ['wp', 'flickr', 'smugmug', 'google', 'picasa', 'zenfolio', 'instagram'].indexOf(shortcode.type) > -1) {
121 iconClass = 'photonic-' + shortcode.type;
122 source = shortcode.type;
123 }
124
125 var title = iconClass === '' ? __('Add Photonic Gallery', 'photonic') : __('Edit Photonic Gallery', 'photonic') + ' (' + __('Source: ', 'photonic') + providers[source] + ')';
126
127 var openFlow = function() {
128 photonicBlockProperties = props;
129 tb_show(title, Photonic_Gutenberg_JS.flow_url);
130 };
131
132 markup.push(
133 el('div', {key: 'photonic-placeholder', className: 'photonic-gallery'},
134 el('a', {className: 'photonic-placeholder-icon photonic ' + iconClass, onClick: openFlow}),
135 title)
136 );
137
138 return(markup);
139 },
140
141 /**
142 * Called when Gutenberg "saves" the block to post_content
143 */
144 save: function( props ) {
145 return null;
146 }
147 } );
148 })(window.wp);
149 });
150