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