* @output wp-admin/js/gallery.js
/* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */
jQuery(document).ready(function($) {
var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
gallerySortableInit = function() {
gallerySortable = $('#media-items').sortable( {
placeholder: 'sorthelper',
// 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);
var all = $('.menu_order_input'), len = all.length;
var order = desc ? (len - i) : (1 + i);
$('.menu_order_input').each( function() {
if ( this.value === '0' || c ) {
$('#asc').on( 'click', function( e ) {
$('#desc').on( 'click', function( e ) {
$('#clear').on( 'click', function( e ) {
$('#showall').on( 'click', function( e ) {
$('#sort-buttons span a').toggle();
$('a.describe-toggle-on').hide();
$('a.describe-toggle-off, table.slidetoggle').show();
$('img.pinkynail').toggle(false);
$('#hideall').on( 'click', function( e ) {
$('#sort-buttons span a').toggle();
$('a.describe-toggle-on').show();
$('a.describe-toggle-off, table.slidetoggle').hide();
$('img.pinkynail').toggle(true);
if ( $('#media-items>*').length > 1 ) {
$('#save-all, #gallery-settings').show();
if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
wpgallery.mcemode = true;
$('#insert-gallery').show();
jQuery(window).on( 'unload', function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup.
return document.getElementById(e);
var t = this, li, q, i, it, w = t.getWin();
li = ('' + document.location.search).replace(/^\?/, '').split('&');
for (i=0; i<li.length; i++) {
q[unescape(it[0])] = unescape(it[1]);
document.domain = q.mce_rdomain;
window.tinymce = w.tinymce;
window.tinyMCE = w.tinyMCE;
t.editor = tinymce.EditorManager.activeEditor;
return window.dialogArguments || opener || parent || top;
var t = this, a, ed = t.editor, g, columns, link, order, orderby;
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] ) {
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();
a = ed.dom.getAttrib(t.el, 'title');
jQuery('#update-gallery').show();
columns = a.match(/columns=['"]([0-9]+)['"]/);
link = a.match(/link=['"]([^'"]+)['"]/i);
order = a.match(/order=['"]([^'"]+)['"]/i);
orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
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];
jQuery('#insert-gallery').show();
var t = this, ed = t.editor, all = '', s;
if ( ! t.mcemode || ! t.is_update ) {
s = '[gallery' + t.getSettings() + ']';
t.getWin().send_to_editor(s);
if ( t.el.nodeName !== 'IMG' ) {
all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
ed.dom.setAttrib(t.el, 'title', all);
getSettings : function() {
if ( I('linkto-file').checked ) {
setUserSetting('galfile', '1');
if ( I('order-desc').checked ) {
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);