author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 21 | 48c4eec2b7e6 |
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 |
||
18 | 91 |
jQuery(window).on( 'unload', function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup. |
0 | 92 |
|
93 |
/* gallery settings */ |
|
9 | 94 |
window.tinymce = null; |
0 | 95 |
|
9 | 96 |
window.wpgallery = { |
0 | 97 |
mcemode : false, |
98 |
editor : {}, |
|
99 |
dom : {}, |
|
100 |
is_update : false, |
|
101 |
el : {}, |
|
102 |
||
103 |
I : function(e) { |
|
104 |
return document.getElementById(e); |
|
105 |
}, |
|
106 |
||
107 |
init: function() { |
|
108 |
var t = this, li, q, i, it, w = t.getWin(); |
|
109 |
||
5 | 110 |
if ( ! t.mcemode ) { |
111 |
return; |
|
112 |
} |
|
0 | 113 |
|
114 |
li = ('' + document.location.search).replace(/^\?/, '').split('&'); |
|
115 |
q = {}; |
|
116 |
for (i=0; i<li.length; i++) { |
|
117 |
it = li[i].split('='); |
|
118 |
q[unescape(it[0])] = unescape(it[1]); |
|
119 |
} |
|
120 |
||
5 | 121 |
if ( q.mce_rdomain ) { |
0 | 122 |
document.domain = q.mce_rdomain; |
5 | 123 |
} |
0 | 124 |
|
16 | 125 |
// Find window & API. |
9 | 126 |
window.tinymce = w.tinymce; |
127 |
window.tinyMCE = w.tinyMCE; |
|
0 | 128 |
t.editor = tinymce.EditorManager.activeEditor; |
129 |
||
130 |
t.setup(); |
|
131 |
}, |
|
132 |
||
133 |
getWin : function() { |
|
134 |
return window.dialogArguments || opener || parent || top; |
|
135 |
}, |
|
136 |
||
137 |
setup : function() { |
|
138 |
var t = this, a, ed = t.editor, g, columns, link, order, orderby; |
|
5 | 139 |
if ( ! t.mcemode ) { |
140 |
return; |
|
141 |
} |
|
0 | 142 |
|
143 |
t.el = ed.selection.getNode(); |
|
144 |
||
5 | 145 |
if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) { |
146 |
if ( ( g = ed.dom.select('img.wpGallery') ) && g[0] ) { |
|
0 | 147 |
t.el = g[0]; |
148 |
} else { |
|
5 | 149 |
if ( getUserSetting('galfile') === '1' ) { |
150 |
t.I('linkto-file').checked = 'checked'; |
|
151 |
} |
|
152 |
if ( getUserSetting('galdesc') === '1' ) { |
|
153 |
t.I('order-desc').checked = 'checked'; |
|
154 |
} |
|
155 |
if ( getUserSetting('galcols') ) { |
|
156 |
t.I('columns').value = getUserSetting('galcols'); |
|
157 |
} |
|
158 |
if ( getUserSetting('galord') ) { |
|
159 |
t.I('orderby').value = getUserSetting('galord'); |
|
160 |
} |
|
0 | 161 |
jQuery('#insert-gallery').show(); |
162 |
return; |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
a = ed.dom.getAttrib(t.el, 'title'); |
|
167 |
a = ed.dom.decode(a); |
|
168 |
||
169 |
if ( a ) { |
|
170 |
jQuery('#update-gallery').show(); |
|
171 |
t.is_update = true; |
|
172 |
||
173 |
columns = a.match(/columns=['"]([0-9]+)['"]/); |
|
174 |
link = a.match(/link=['"]([^'"]+)['"]/i); |
|
175 |
order = a.match(/order=['"]([^'"]+)['"]/i); |
|
176 |
orderby = a.match(/orderby=['"]([^'"]+)['"]/i); |
|
177 |
||
5 | 178 |
if ( link && link[1] ) { |
179 |
t.I('linkto-file').checked = 'checked'; |
|
180 |
} |
|
181 |
if ( order && order[1] ) { |
|
182 |
t.I('order-desc').checked = 'checked'; |
|
183 |
} |
|
184 |
if ( columns && columns[1] ) { |
|
185 |
t.I('columns').value = '' + columns[1]; |
|
186 |
} |
|
187 |
if ( orderby && orderby[1] ) { |
|
188 |
t.I('orderby').value = orderby[1]; |
|
189 |
} |
|
0 | 190 |
} else { |
191 |
jQuery('#insert-gallery').show(); |
|
192 |
} |
|
193 |
}, |
|
194 |
||
195 |
update : function() { |
|
196 |
var t = this, ed = t.editor, all = '', s; |
|
197 |
||
198 |
if ( ! t.mcemode || ! t.is_update ) { |
|
5 | 199 |
s = '[gallery' + t.getSettings() + ']'; |
0 | 200 |
t.getWin().send_to_editor(s); |
201 |
return; |
|
202 |
} |
|
203 |
||
5 | 204 |
if ( t.el.nodeName !== 'IMG' ) { |
205 |
return; |
|
206 |
} |
|
0 | 207 |
|
5 | 208 |
all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) ); |
0 | 209 |
all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, ''); |
210 |
all += t.getSettings(); |
|
211 |
||
212 |
ed.dom.setAttrib(t.el, 'title', all); |
|
213 |
t.getWin().tb_remove(); |
|
214 |
}, |
|
215 |
||
216 |
getSettings : function() { |
|
217 |
var I = this.I, s = ''; |
|
218 |
||
219 |
if ( I('linkto-file').checked ) { |
|
220 |
s += ' link="file"'; |
|
221 |
setUserSetting('galfile', '1'); |
|
222 |
} |
|
223 |
||
224 |
if ( I('order-desc').checked ) { |
|
225 |
s += ' order="DESC"'; |
|
226 |
setUserSetting('galdesc', '1'); |
|
227 |
} |
|
228 |
||
5 | 229 |
if ( I('columns').value !== 3 ) { |
230 |
s += ' columns="' + I('columns').value + '"'; |
|
0 | 231 |
setUserSetting('galcols', I('columns').value); |
232 |
} |
|
233 |
||
5 | 234 |
if ( I('orderby').value !== 'menu_order' ) { |
235 |
s += ' orderby="' + I('orderby').value + '"'; |
|
0 | 236 |
setUserSetting('galord', I('orderby').value); |
237 |
} |
|
238 |
||
239 |
return s; |
|
240 |
} |
|
241 |
}; |