PluginProbe
QuadMenu – Mega Menu / 1.8.8
QuadMenu – Mega Menu v1.8.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / lib / ReduxCore / inc / fields / gallery / field_gallery.js

field_gallery.js in QuadMenu – Mega Menu 1.8.8, at lib/ReduxCore/inc/fields/gallery/field_gallery.js

137 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global redux_change, wp */
2
3 /*global redux_change, redux*/
4
5 (function( $ ) {
6 "use strict";
7
8 redux.field_objects = redux.field_objects || {};
9 redux.field_objects.gallery = redux.field_objects.gallery || {};
10
11 redux.field_objects.gallery.init = function( selector ) {
12
13
14 if ( !selector ) {
15 selector = $( document ).find( '.redux-container-gallery:visible' );
16 }
17
18 $( selector ).each(
19 function() {
20 var el = $( this );
21 var parent = el;
22 if ( !el.hasClass( 'redux-field-container' ) ) {
23 parent = el.parents( '.redux-field-container:first' );
24 }
25 if ( parent.is( ":hidden" ) ) { // Skip hidden fields
26 return;
27 }
28 if ( parent.hasClass( 'redux-field-init' ) ) {
29 parent.removeClass( 'redux-field-init' );
30 } else {
31 return;
32 }
33 // When the user clicks on the Add/Edit gallery button, we need to display the gallery editing
34 el.on(
35 {
36 click: function( event ) {
37 //console.log(event);
38 // hide gallery settings used for posts/pages
39 wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
40 // render: function(){
41 // console.log(wp.media.view);
42 // this.update.apply( this, ['size'] );
43 // return this;
44 // },
45 template: function(view){
46 //console.log(view);
47
48 return;// wp.media.template('gallery-settings')(view);
49 }
50 });
51
52 var current_gallery = $( this ).closest( 'fieldset' );
53
54 if ( event.currentTarget.id === 'clear-gallery' ) {
55 //remove value from input
56
57 var rmVal = current_gallery.find( '.gallery_values' ).val( '' );
58
59 //remove preview images
60 current_gallery.find( ".screenshot" ).html( "" );
61
62 return;
63
64 }
65
66 // Make sure the media gallery API exists
67 if ( typeof wp === 'undefined' || !wp.media || !wp.media.gallery ) {
68 return;
69 }
70 event.preventDefault();
71
72 // Activate the media editor
73 var $$ = $( this );
74
75 var val = current_gallery.find( '.gallery_values' ).val();
76 var final;
77
78 if ( !val ) {
79 final = '[gallery ids="0"]';
80 } else {
81 final = '[gallery ids="' + val + '"]';
82 }
83
84
85 var frame = wp.media.gallery.edit( final );
86
87 if (!val) {
88 var uploader = $('body').find('#' + frame.el.id);
89 var inline = uploader.find('.uploader-inline');
90 var spinner = uploader.find('.media-toolbar .spinner');
91
92 setTimeout(
93 function(){
94 if (inline.hasClass('hidden')) {
95 inline.removeClass('hidden');
96 spinner.removeClass('is-active');
97 }
98 }, 400
99 );
100 }
101
102 // When the gallery-edit state is updated, copy the attachment ids across
103 frame.state( 'gallery-edit' ).on(
104 'update', function( selection ) {
105
106 //clear screenshot div so we can append new selected images
107 current_gallery.find( ".screenshot" ).html( "" );
108
109 var element, preview_html = "", preview_img;
110 var ids = selection.models.map(
111 function( e ) {
112 element = e.toJSON();
113 //preview_img = typeof element.sizes.thumbnail !== 'undefined' ? element.sizes.thumbnail.url : element.url;
114 preview_img = (typeof element.sizes !== "undefined" && typeof element.sizes.thumbnail !== 'undefined') ? element.sizes.thumbnail.url : element.url;
115
116 preview_html = "<a class='of-uploaded-image' href='" + preview_img + "'><img class='redux-option-image' src='" + preview_img + "' alt='' /></a>";
117 current_gallery.find( ".screenshot" ).append( preview_html );
118
119 return e.id;
120 }
121 );
122
123 current_gallery.find( '.gallery_values' ).val( ids.join( ',' ) );
124 redux_change( current_gallery.find( '.gallery_values' ) );
125 frame.detach();
126 }
127 );
128
129 return false;
130 }
131 }, '.gallery-attachments'
132 );
133 }
134 );
135
136 };
137 })( jQuery );