jQuery(document).ready(function($) { var gallerySortable, gallerySortableInit, w, desc = false; gallerySortableInit = function() { gallerySortable = $('#media-items').sortable( { items: '.media-item', placeholder: 'sorthelper', axis: 'y', distance: 2, 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); }); } } ); } 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;}); $('#showall').click(function(){ $('#sort-buttons span a').toggle(); $('a.describe-toggle-on').hide(); $('a.describe-toggle-off, table.slidetoggle').show(); return false; }); $('#hideall').click(function(){ $('#sort-buttons span a').toggle(); $('a.describe-toggle-on').show(); $('a.describe-toggle-off, table.slidetoggle').hide(); return false; }); // initialize sortable gallerySortableInit(); clearAll(); 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