2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/gallery.js
|
|
|
|
*/
|
|
|
|
|
2018-08-19 09:33:24 -04:00
|
|
|
/* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */
|
2013-11-19 06:10:09 -05:00
|
|
|
|
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() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// When an update has occurred, adjust the order for each item.
|
2012-08-22 20:04:18 -04:00
|
|
|
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
|
|
|
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#asc').on( 'click', function( e ) {
|
2015-10-08 21:27:27 -04:00
|
|
|
e.preventDefault();
|
2013-11-19 06:10:09 -05:00
|
|
|
desc = false;
|
|
|
|
sortIt();
|
|
|
|
});
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#desc').on( 'click', function( e ) {
|
2015-10-08 21:27:27 -04:00
|
|
|
e.preventDefault();
|
2013-11-19 06:10:09 -05:00
|
|
|
desc = true;
|
|
|
|
sortIt();
|
|
|
|
});
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#clear').on( 'click', function( e ) {
|
2015-10-08 21:27:27 -04:00
|
|
|
e.preventDefault();
|
2013-11-19 06:10:09 -05:00
|
|
|
clearAll(1);
|
|
|
|
});
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#showall').on( 'click', function( e ) {
|
2015-10-08 21:27:27 -04:00
|
|
|
e.preventDefault();
|
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);
|
|
|
|
});
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#hideall').on( 'click', function( e ) {
|
2015-10-08 21:27:27 -04:00
|
|
|
e.preventDefault();
|
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);
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Initialize sortable.
|
2012-08-22 20:04:18 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-23 14:45:04 -05:00
|
|
|
jQuery(window).on( 'unload', function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup.
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
/* gallery settings */
|
2018-08-19 09:33:24 -04:00
|
|
|
window.tinymce = null;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2018-08-19 09:33:24 -04:00
|
|
|
window.wpgallery = {
|
2012-08-22 20:04:18 -04:00
|
|
|
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
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Find window & API.
|
2018-08-19 09:33:24 -04:00
|
|
|
window.tinymce = w.tinymce;
|
|
|
|
window.tinyMCE = w.tinyMCE;
|
2012-08-22 20:04:18 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|