Skip to content

Commit ca1d459

Browse files
committed
Hide / show gallery settings
1 parent 8bb0c57 commit ca1d459

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

class-gg-core.php

-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public function createSettings() {
9999

100100
public function renderGallery( $output, $atts ) {
101101

102-
if ( $this)
103-
104102
/**
105103
* Get the attachments that we will display
106104
*/

gambit-gallery.php

+24-19
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public function loadAdminScripts() {
109109
array(),
110110
GG_VERSION
111111
);
112+
113+
wp_enqueue_script(
114+
GG_SLUG . '-admin',
115+
plugins_url( 'js/admin.js', __FILE__ ),
116+
array( 'jquery' ),
117+
GG_VERSION
118+
);
112119
}
113120

114121

@@ -138,25 +145,23 @@ public function renderGallerySettings() {
138145
</script>
139146

140147
<script>
141-
142-
jQuery(document).ready(function(){
143-
144-
// add your shortcode attribute and its default value to the
145-
// gallery settings list; $.extend should work as well...
146-
_.extend(wp.media.gallery.defaults,
147-
<?php echo json_encode( $attributeDefaults ) ?>
148-
);
149-
150-
// merge default gallery settings template with yours
151-
wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
152-
template: function(view){
153-
return wp.media.template('gallery-settings')(view)
154-
+ wp.media.template('<?php echo GG_SLUG ?>-settings')(view);
155-
}
156-
});
157-
158-
});
159-
148+
jQuery(document).ready(function($){
149+
150+
// add your shortcode attribute and its default value to the
151+
// gallery settings list; $.extend should work as well...
152+
_.extend(wp.media.gallery.defaults,
153+
<?php echo json_encode( $attributeDefaults ) ?>
154+
);
155+
156+
// merge default gallery settings template with yours
157+
wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
158+
template: function(view){
159+
return wp.media.template('gallery-settings')(view)
160+
+ wp.media.template('<?php echo GG_SLUG ?>-settings')(view);
161+
}
162+
});
163+
164+
});
160165
</script>
161166
<?php
162167
}

js/admin.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
jQuery(document).ready(function($) {
2+
"use strict";
3+
4+
5+
// Trigger stuff on change
6+
var modalIsVisible = false;
7+
setInterval( function() {
8+
$ = jQuery;
9+
if ( modalIsVisible !== $('.media-modal').is(':visible') ) {
10+
if ( ! modalIsVisible ) {
11+
$('.setting.gambit-gallery').find('select, input').trigger('change');
12+
}
13+
modalIsVisible = $('.media-modal').is(':visible');
14+
}
15+
}, 500 );
16+
17+
18+
// Hide the size because we won't use it
19+
// Show gambit gallery settings if enabled
20+
$('body').on('change', '[data-setting="gambit_gallery"]', function() {
21+
if ( $(this).val() === 'enabled' ) {
22+
$('.gallery-settings .setting.size').css('opacity', '.5');
23+
$('.setting.gambit-gallery').filter(':not(:eq(0))').show();
24+
} else {
25+
$('.gallery-settings .setting.size').css('opacity', '1');
26+
$('.setting.gambit-gallery').filter(':not(:eq(0))').hide();
27+
}
28+
});
29+
});

js/min/admin-min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)