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