2013-11-19 06:10:09 -05:00
|
|
|
/* global unescape, getUserSetting, setUserSetting */
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
jQuery(document).ready(function($) {
|
2013-11-19 06:10:09 -05:00
|
|
|
var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
gallerySortableInit = function() {
|
|
|
|
gallerySortable = $('#media-items').sortable( {
|
|
|
|
items: 'div.media-item',
|
|
|
|
placeholder: 'sorthelper',
|
|
|
|
axis: 'y',
|
|
|
|
distance: 2,
|
|
|
|
handle: 'div.filename',
|
2013-11-19 06:10:09 -05:00
|
|
|
stop: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
// When an update has occurred, adjust the order for each item
|
|
|
|
var all = $('#media-items').sortable('toArray'), len = all.length;
|
|
|
|
$.each(all, function(i, id) {
|
|
|
|
var order = desc ? (len - i) : (1 + i);
|
|
|
|
$('#' + id + ' .menu_order input').val(order);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} );
|
2013-11-19 06:10:09 -05:00
|
|
|
};
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
sortIt = function() {
|
|
|
|
var all = $('.menu_order_input'), len = all.length;
|
|
|
|
all.each(function(i){
|
|
|
|
var order = desc ? (len - i) : (1 + i);
|
|
|
|
$(this).val(order);
|
|
|
|
});
|
2013-11-19 06:10:09 -05:00
|
|
|
};
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
clearAll = function(c) {
|
|
|
|
c = c || 0;
|
2013-11-19 06:10:09 -05:00
|
|
|
$('.menu_order_input').each( function() {
|
|
|
|
if ( this.value === '0' || c ) {
|
|
|
|
this.value = '';
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
2013-11-19 06:10:09 -05:00
|
|
|
};
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
$('#asc').click( function() {
|
|
|
|
desc = false;
|
|
|
|
sortIt();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#desc').click( function() {
|
|
|
|
desc = true;
|
|
|
|
sortIt();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#clear').click( function() {
|
|
|
|
clearAll(1);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#showall').click( function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
$('#sort-buttons span a').toggle();
|
|
|
|
$('a.describe-toggle-on').hide();
|
|
|
|
$('a.describe-toggle-off, table.slidetoggle').show();
|
|
|
|
$('img.pinkynail').toggle(false);
|
|
|
|
return false;
|
|
|
|
});
|
2013-11-19 06:10:09 -05:00
|
|
|
$('#hideall').click( function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
$('#sort-buttons span a').toggle();
|
|
|
|
$('a.describe-toggle-on').show();
|
|
|
|
$('a.describe-toggle-off, table.slidetoggle').hide();
|
|
|
|
$('img.pinkynail').toggle(true);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// initialize sortable
|
|
|
|
gallerySortableInit();
|
|
|
|
clearAll();
|
|
|
|
|
|
|
|
if ( $('#media-items>*').length > 1 ) {
|
|
|
|
w = wpgallery.getWin();
|
|
|
|
|
|
|
|
$('#save-all, #gallery-settings').show();
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
wpgallery.mcemode = true;
|
|
|
|
wpgallery.init();
|
|
|
|
} else {
|
|
|
|
$('#insert-gallery').show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery(window).unload( function () { tinymce = tinyMCE = wpgallery = null; } ); // Cleanup
|
|
|
|
|
|
|
|
/* gallery settings */
|
|
|
|
var tinymce = null, tinyMCE, wpgallery;
|
|
|
|
|
|
|
|
wpgallery = {
|
|
|
|
mcemode : false,
|
|
|
|
editor : {},
|
|
|
|
dom : {},
|
|
|
|
is_update : false,
|
|
|
|
el : {},
|
|
|
|
|
|
|
|
I : function(e) {
|
|
|
|
return document.getElementById(e);
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
var t = this, li, q, i, it, w = t.getWin();
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( ! t.mcemode ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
li = ('' + document.location.search).replace(/^\?/, '').split('&');
|
|
|
|
q = {};
|
|
|
|
for (i=0; i<li.length; i++) {
|
|
|
|
it = li[i].split('=');
|
|
|
|
q[unescape(it[0])] = unescape(it[1]);
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( q.mce_rdomain ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
document.domain = q.mce_rdomain;
|
2013-11-19 06:10:09 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// Find window & API
|
|
|
|
tinymce = w.tinymce;
|
|
|
|
tinyMCE = w.tinyMCE;
|
|
|
|
t.editor = tinymce.EditorManager.activeEditor;
|
|
|
|
|
|
|
|
t.setup();
|
|
|
|
},
|
|
|
|
|
|
|
|
getWin : function() {
|
|
|
|
return window.dialogArguments || opener || parent || top;
|
|
|
|
},
|
|
|
|
|
|
|
|
setup : function() {
|
|
|
|
var t = this, a, ed = t.editor, g, columns, link, order, orderby;
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( ! t.mcemode ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
t.el = ed.selection.getNode();
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
|
|
|
|
if ( ( g = ed.dom.select('img.wpGallery') ) && g[0] ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
t.el = g[0];
|
|
|
|
} else {
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( getUserSetting('galfile') === '1' ) {
|
|
|
|
t.I('linkto-file').checked = 'checked';
|
|
|
|
}
|
|
|
|
if ( getUserSetting('galdesc') === '1' ) {
|
|
|
|
t.I('order-desc').checked = 'checked';
|
|
|
|
}
|
|
|
|
if ( getUserSetting('galcols') ) {
|
|
|
|
t.I('columns').value = getUserSetting('galcols');
|
|
|
|
}
|
|
|
|
if ( getUserSetting('galord') ) {
|
|
|
|
t.I('orderby').value = getUserSetting('galord');
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
jQuery('#insert-gallery').show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a = ed.dom.getAttrib(t.el, 'title');
|
|
|
|
a = ed.dom.decode(a);
|
|
|
|
|
|
|
|
if ( a ) {
|
|
|
|
jQuery('#update-gallery').show();
|
|
|
|
t.is_update = true;
|
|
|
|
|
|
|
|
columns = a.match(/columns=['"]([0-9]+)['"]/);
|
|
|
|
link = a.match(/link=['"]([^'"]+)['"]/i);
|
|
|
|
order = a.match(/order=['"]([^'"]+)['"]/i);
|
|
|
|
orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( link && link[1] ) {
|
|
|
|
t.I('linkto-file').checked = 'checked';
|
|
|
|
}
|
|
|
|
if ( order && order[1] ) {
|
|
|
|
t.I('order-desc').checked = 'checked';
|
|
|
|
}
|
|
|
|
if ( columns && columns[1] ) {
|
|
|
|
t.I('columns').value = '' + columns[1];
|
|
|
|
}
|
|
|
|
if ( orderby && orderby[1] ) {
|
|
|
|
t.I('orderby').value = orderby[1];
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
|
|
|
jQuery('#insert-gallery').show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
update : function() {
|
|
|
|
var t = this, ed = t.editor, all = '', s;
|
|
|
|
|
|
|
|
if ( ! t.mcemode || ! t.is_update ) {
|
2013-11-19 06:10:09 -05:00
|
|
|
s = '[gallery' + t.getSettings() + ']';
|
2012-08-22 20:04:18 -04:00
|
|
|
t.getWin().send_to_editor(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( t.el.nodeName !== 'IMG' ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
|
|
|
|
all += t.getSettings();
|
|
|
|
|
|
|
|
ed.dom.setAttrib(t.el, 'title', all);
|
|
|
|
t.getWin().tb_remove();
|
|
|
|
},
|
|
|
|
|
|
|
|
getSettings : function() {
|
|
|
|
var I = this.I, s = '';
|
|
|
|
|
|
|
|
if ( I('linkto-file').checked ) {
|
|
|
|
s += ' link="file"';
|
|
|
|
setUserSetting('galfile', '1');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( I('order-desc').checked ) {
|
|
|
|
s += ' order="DESC"';
|
|
|
|
setUserSetting('galdesc', '1');
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( I('columns').value !== 3 ) {
|
|
|
|
s += ' columns="' + I('columns').value + '"';
|
2012-08-22 20:04:18 -04:00
|
|
|
setUserSetting('galcols', I('columns').value);
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:10:09 -05:00
|
|
|
if ( I('orderby').value !== 'menu_order' ) {
|
|
|
|
s += ' orderby="' + I('orderby').value + '"';
|
2012-08-22 20:04:18 -04:00
|
|
|
setUserSetting('galord', I('orderby').value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|