jQuery(document).ready(function($) { var gallerySortable, gallerySortableInit, w, desc = false; gallerySortableInit = function() { gallerySortable = $('#media-items').sortable( { items: 'div.media-item', placeholder: 'sorthelper', axis: 'y', distance: 2, handle: 'div.filename', 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(); $('img.pinkynail').toggle(false); return false; }); $('#hideall').click(function(){ $('#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(); 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; itbWidth?tbWidth:f-90,c=tbHeight&&e-60>tbHeight?tbHeight:e-60,d.size()&&(d.width(b).height(c),a("#TB_iframeContent").width(b).height(c-27),d.css({"margin-left":"-"+parseInt(b/2,10)+"px"}),"undefined"!=typeof document.body.style.maxWidth&&d.css({top:"30px","margin-top":"0"}))},thickDims(),a(window).resize(function(){thickDims()}),a("a.thickbox-preview").click(function(){tb_click.call(this);var b,c,d=a(this).parents(".available-theme").find(".activatelink"), && 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; } };