PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.30
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.30
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.30, at include/scripts/admin/block.js

151 lines 4.3 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 {
46 type: 'block',
47 blocks: ['core/gallery'],
48 transform: function(attributes) {
49 var images = attributes.images;
50 var ids = '';
51 $(images).each(function(idx, val) {
52 ids += val.id + ',';
53 });
54 if (ids.length > 0) {
55 ids = ids.slice(0, -1);
56 }
57 var sc = {
58 type: 'wp',
59 ids: ids
60 };
61 return wp.blocks.createBlock('photonic/gallery', {
62 shortcode: JSON.stringify(sc)
63 });
64 }
65 }
66 ]/*,
67 to: [
68 {
69 type: 'block',
70 blocks: ['core/gallery'],
71 isMatch: function(attributes) {
72 if (attributes.shortcode === undefined || attributes.shortcode === null) {
73 return true;
74 }
75 var scAttr = JSON.parse(attributes.shortcode);
76 return scAttr.type === undefined || scAttr.type === null || scAttr.type === 'wp';
77 },
78 transform: function(attributes) {
79 var scAttr = JSON.parse(attributes.shortcode);
80 var gAttr = _.pick(scAttr, 'caption', 'order', 'orderby', 'id', 'itemtag', 'icontag', 'captiontag', 'size', 'include', 'ids', 'exclude', 'thumb_width', 'thumb_height', 'columns');
81 if (gAttr.ids !== undefined && gAttr.ids !== null && (gAttr.include === undefined || gAttr.include === null)) {
82 gAttr.include = gAttr.ids;
83 }
84 console.log(gAttr);
85
86 return wp.blocks.createBlock('core/gallery', gAttr);
87 }
88 }
89 ]
90 */ },
91
92 attributes: {
93 shortcode: {
94 type: 'string'
95 }
96 },
97
98 /**
99 * Called when Gutenberg initially loads the block.
100 */
101 edit: function( props ) {
102 var markup = [], iconClass = '';
103 var shortcode = props.attributes.shortcode || '{}';
104 shortcode = JSON.parse(shortcode);
105
106 var providers = {
107 'wp': 'WordPress',
108 'flickr': 'Flickr',
109 'smugmug': 'SmugMug',
110 'google': 'Google Photos',
111 'picasa': 'Picasa',
112 'zenfolio': 'Zenfolio',
113 'instagram': 'Instagram'
114 };
115 var source;
116
117 if (!$.isEmptyObject(shortcode) && (shortcode.type === undefined || shortcode.type === 'default')) {
118 iconClass = 'photonic-wp';
119 source = 'wp';
120 }
121 else if (shortcode.type !== undefined && ['wp', 'flickr', 'smugmug', 'google', 'picasa', 'zenfolio', 'instagram'].indexOf(shortcode.type) > -1) {
122 iconClass = 'photonic-' + shortcode.type;
123 source = shortcode.type;
124 }
125
126 var title = iconClass === '' ? __('Add Photonic Gallery', 'photonic') : __('Edit Photonic Gallery', 'photonic') + ' (' + __('Source: ', 'photonic') + providers[source] + ')';
127
128 var openFlow = function() {
129 photonicBlockProperties = props;
130 tb_show(title, Photonic_Gutenberg_JS.flow_url);
131 };
132
133 markup.push(
134 el('div', {key: 'photonic-placeholder', className: 'photonic-gallery'},
135 el('a', {className: 'photonic-placeholder-icon photonic ' + iconClass, onClick: openFlow}),
136 title)
137 );
138
139 return(markup);
140 },
141
142 /**
143 * Called when Gutenberg "saves" the block to post_content
144 */
145 save: function( props ) {
146 return null;
147 }
148 } );
149 })(window.wp);
150 });
151