1
/* global unescape, getUserSetting, setUserSetting */
3
jQuery(document).ready(function($) {
4
var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
6
gallerySortableInit = function() {
7
gallerySortable = $('#media-items').sortable( {
8
items: 'div.media-item',
9
placeholder: 'sorthelper',
12
handle: 'div.filename',
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);
25
var all = $('.menu_order_input'), len = all.length;
27
var order = desc ? (len - i) : (1 + i);
32
clearAll = function(c) {
34
$('.menu_order_input').each( function() {
35
if ( this.value === '0' || c ) {
41
$('#asc').click( function() {
46
$('#desc').click( function() {
51
$('#clear').click( function() {
55
$('#showall').click( function() {
56
$('#sort-buttons span a').toggle();
57
$('a.describe-toggle-on').hide();
58
$('a.describe-toggle-off, table.slidetoggle').show();
59
$('img.pinkynail').toggle(false);
62
$('#hideall').click( function() {
63
$('#sort-buttons span a').toggle();
64
$('a.describe-toggle-on').show();
65
$('a.describe-toggle-off, table.slidetoggle').hide();
66
$('img.pinkynail').toggle(true);
70
// initialize sortable
71
gallerySortableInit();
74
if ( $('#media-items>*').length > 1 ) {
75
w = wpgallery.getWin();
77
$('#save-all, #gallery-settings').show();
78
if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
79
wpgallery.mcemode = true;
82
$('#insert-gallery').show();
87
jQuery(window).unload( function () { tinymce = tinyMCE = wpgallery = null; } ); // Cleanup
89
/* gallery settings */
90
var tinymce = null, tinyMCE, wpgallery;
100
return document.getElementById(e);
104
var t = this, li, q, i, it, w = t.getWin();
110
li = ('' + document.location.search).replace(/^\?/, '').split('&');
112
for (i=0; i<li.length; i++) {
113
it = li[i].split('=');
114
q[unescape(it[0])] = unescape(it[1]);
117
if ( q.mce_rdomain ) {
118
document.domain = q.mce_rdomain;
124
t.editor = tinymce.EditorManager.activeEditor;
129
getWin : function() {
130
return window.dialogArguments || opener || parent || top;
134
var t = this, a, ed = t.editor, g, columns, link, order, orderby;
139
t.el = ed.selection.getNode();
141
if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
142
if ( ( g = ed.dom.select('img.wpGallery') ) && g[0] ) {
145
if ( getUserSetting('galfile') === '1' ) {
146
t.I('linkto-file').checked = 'checked';
148
if ( getUserSetting('galdesc') === '1' ) {
149
t.I('order-desc').checked = 'checked';
151
if ( getUserSetting('galcols') ) {
152
t.I('columns').value = getUserSetting('galcols');
154
if ( getUserSetting('galord') ) {
155
t.I('orderby').value = getUserSetting('galord');
157
jQuery('#insert-gallery').show();
162
a = ed.dom.getAttrib(t.el, 'title');
163
a = ed.dom.decode(a);
166
jQuery('#update-gallery').show();
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);
174
if ( link && link[1] ) {
175
t.I('linkto-file').checked = 'checked';
177
if ( order && order[1] ) {
178
t.I('order-desc').checked = 'checked';
180
if ( columns && columns[1] ) {
181
t.I('columns').value = '' + columns[1];
183
if ( orderby && orderby[1] ) {
184
t.I('orderby').value = orderby[1];
187
jQuery('#insert-gallery').show();
191
update : function() {
192
var t = this, ed = t.editor, all = '', s;
194
if ( ! t.mcemode || ! t.is_update ) {
195
s = '[gallery' + t.getSettings() + ']';
196
t.getWin().send_to_editor(s);
200
if ( t.el.nodeName !== 'IMG' ) {
204
all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
205
all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
206
all += t.getSettings();
208
ed.dom.setAttrib(t.el, 'title', all);
209
t.getWin().tb_remove();
212
getSettings : function() {
213
var I = this.I, s = '';
215
if ( I('linkto-file').checked ) {
217
setUserSetting('galfile', '1');
220
if ( I('order-desc').checked ) {
221
s += ' order="DESC"';
222
setUserSetting('galdesc', '1');
225
if ( I('columns').value !== 3 ) {
226
s += ' columns="' + I('columns').value + '"';
227
setUserSetting('galcols', I('columns').value);
230
if ( I('orderby').value !== 'menu_order' ) {
231
s += ' orderby="' + I('orderby').value + '"';
232
setUserSetting('galord', I('orderby').value);