2009-01-02 10:08:58 -05:00
|
|
|
jQuery(document).ready(function($) {
|
2009-03-25 13:20:03 -04:00
|
|
|
var gallerySortable, gallerySortableInit, w, desc = false;
|
2009-01-02 10:08:58 -05:00
|
|
|
|
|
|
|
gallerySortableInit = function() {
|
|
|
|
gallerySortable = $('#media-items').sortable( {
|
2009-09-10 18:07:33 -04:00
|
|
|
items: 'div.media-item',
|
2009-01-02 10:08:58 -05:00
|
|
|
placeholder: 'sorthelper',
|
|
|
|
axis: 'y',
|
|
|
|
distance: 2,
|
2009-09-10 18:07:33 -04:00
|
|
|
handle: 'div.filename',
|
2009-03-25 13:20:03 -04:00
|
|
|
stop: function(e, ui) {
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
}
|
2009-01-02 10:08:58 -05:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:05:09 -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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
clearAll = function(c) {
|
|
|
|
c = c || 0;
|
|
|
|
$('.menu_order_input').each(function(){
|
|
|
|
if ( this.value == '0' || c ) this.value = '';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#asc').click(function(){desc = false; sortIt(); return false;});
|
|
|
|
$('#desc').click(function(){desc = true; sortIt(); return false;});
|
|
|
|
$('#clear').click(function(){clearAll(1); return false;});
|
2009-05-17 08:29:58 -04:00
|
|
|
$('#showall').click(function(){
|
|
|
|
$('#sort-buttons span a').toggle();
|
|
|
|
$('a.describe-toggle-on').hide();
|
|
|
|
$('a.describe-toggle-off, table.slidetoggle').show();
|
2011-09-30 20:12:39 -04:00
|
|
|
$('img.pinkynail').toggle(false);
|
2009-05-17 08:29:58 -04:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#hideall').click(function(){
|
|
|
|
$('#sort-buttons span a').toggle();
|
|
|
|
$('a.describe-toggle-on').show();
|
|
|
|
$('a.describe-toggle-off, table.slidetoggle').hide();
|
2011-09-30 20:12:39 -04:00
|
|
|
$('img.pinkynail').toggle(true);
|
2009-05-17 08:29:58 -04:00
|
|
|
return false;
|
|
|
|
});
|
2009-03-16 09:05:09 -04:00
|
|
|
|
2009-01-02 10:08:58 -05:00
|
|
|
// initialize sortable
|
|
|
|
gallerySortableInit();
|
2009-03-16 09:05:09 -04:00
|
|
|
clearAll();
|
2009-01-02 10:08:58 -05:00
|
|
|
|
|
|
|
if ( $('#media-items>*').length > 1 ) {
|
|
|
|
w = wpgallery.getWin();
|
|
|
|
|
|
|
|
$('#save-all, #gallery-settings').show();
|
|
|
|
if ( typeof w.tinyMCE != 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
if ( ! t.mcemode ) return;
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q.mce_rdomain)
|
|
|
|
document.domain = q.mce_rdomain;
|
|
|
|
|
|
|
|
// 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() {
|
2009-03-25 13:20:03 -04:00
|
|
|
var t = this, a, ed = t.editor, g, columns, link, order, orderby;
|
2009-01-02 10:08:58 -05:00
|
|
|
if ( ! t.mcemode ) return;
|
|
|
|
|
|
|
|
t.el = ed.selection.getNode();
|
|
|
|
|
|
|
|
if ( t.el.nodeName != 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
|
|
|
|
if ( (g = ed.dom.select('img.wpGallery')) && g[0] ) {
|
|
|
|
t.el = g[0];
|
|
|
|
} else {
|
|
|
|
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');
|
|
|
|
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;
|
|
|
|
|
2009-03-25 13:20:03 -04:00
|
|
|
columns = a.match(/columns=['"]([0-9]+)['"]/);
|
|
|
|
link = a.match(/link=['"]([^'"]+)['"]/i);
|
|
|
|
order = a.match(/order=['"]([^'"]+)['"]/i);
|
|
|
|
orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
|
2009-01-02 10:08:58 -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];
|
|
|
|
} else {
|
|
|
|
jQuery('#insert-gallery').show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
update : function() {
|
|
|
|
var t = this, ed = t.editor, all = '', s;
|
|
|
|
|
|
|
|
if ( ! t.mcemode || ! t.is_update ) {
|
|
|
|
s = '[gallery'+t.getSettings()+']';
|
|
|
|
t.getWin().send_to_editor(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t.el.nodeName != 'IMG') return;
|
|
|
|
|
|
|
|
all = ed.dom.decode(ed.dom.getAttrib(t.el, 'title'));
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( I('columns').value != 3 ) {
|
|
|
|
s += ' columns="'+I('columns').value+'"';
|
|
|
|
setUserSetting('galcols', I('columns').value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( I('orderby').value != 'menu_order' ) {
|
|
|
|
s += ' orderby="'+I('orderby').value+'"';
|
|
|
|
setUserSetting('galord', I('orderby').value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|