| [ Index ] |
PHP Cross Reference of Wordpress 2.9.1 |
[Summary view] [Print] [Text view]
1 jQuery(document).ready(function($) { 2 var gallerySortable, gallerySortableInit, w, desc = false; 3 4 gallerySortableInit = function() { 5 gallerySortable = $('#media-items').sortable( { 6 items: 'div.media-item', 7 placeholder: 'sorthelper', 8 axis: 'y', 9 distance: 2, 10 handle: 'div.filename', 11 stop: function(e, ui) { 12 // When an update has occurred, adjust the order for each item 13 var all = $('#media-items').sortable('toArray'), len = all.length; 14 $.each(all, function(i, id) { 15 var order = desc ? (len - i) : (1 + i); 16 $('#' + id + ' .menu_order input').val(order); 17 }); 18 } 19 } ); 20 } 21 22 sortIt = function() { 23 var all = $('.menu_order_input'), len = all.length; 24 all.each(function(i){ 25 var order = desc ? (len - i) : (1 + i); 26 $(this).val(order); 27 }); 28 } 29 30 clearAll = function(c) { 31 c = c || 0; 32 $('.menu_order_input').each(function(){ 33 if ( this.value == '0' || c ) this.value = ''; 34 }); 35 } 36 37 $('#asc').click(function(){desc = false; sortIt(); return false;}); 38 $('#desc').click(function(){desc = true; sortIt(); return false;}); 39 $('#clear').click(function(){clearAll(1); return false;}); 40 $('#showall').click(function(){ 41 $('#sort-buttons span a').toggle(); 42 $('a.describe-toggle-on').hide(); 43 $('a.describe-toggle-off, table.slidetoggle').show(); 44 return false; 45 }); 46 $('#hideall').click(function(){ 47 $('#sort-buttons span a').toggle(); 48 $('a.describe-toggle-on').show(); 49 $('a.describe-toggle-off, table.slidetoggle').hide(); 50 return false; 51 }); 52 53 // initialize sortable 54 gallerySortableInit(); 55 clearAll(); 56 57 if ( $('#media-items>*').length > 1 ) { 58 w = wpgallery.getWin(); 59 60 $('#save-all, #gallery-settings').show(); 61 if ( typeof w.tinyMCE != 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) { 62 wpgallery.mcemode = true; 63 wpgallery.init(); 64 } else { 65 $('#insert-gallery').show(); 66 } 67 } 68 }); 69 70 jQuery(window).unload( function () { tinymce = tinyMCE = wpgallery = null; } ); // Cleanup 71 72 /* gallery settings */ 73 var tinymce = null, tinyMCE, wpgallery; 74 75 wpgallery = { 76 mcemode : false, 77 editor : {}, 78 dom : {}, 79 is_update : false, 80 el : {}, 81 82 I : function(e) { 83 return document.getElementById(e); 84 }, 85 86 init: function() { 87 var t = this, li, q, i, it, w = t.getWin(); 88 89 if ( ! t.mcemode ) return; 90 91 li = ('' + document.location.search).replace(/^\?/, '').split('&'); 92 q = {}; 93 for (i=0; i<li.length; i++) { 94 it = li[i].split('='); 95 q[unescape(it[0])] = unescape(it[1]); 96 } 97 98 if (q.mce_rdomain) 99 document.domain = q.mce_rdomain; 100 101 // Find window & API 102 tinymce = w.tinymce; 103 tinyMCE = w.tinyMCE; 104 t.editor = tinymce.EditorManager.activeEditor; 105 106 t.setup(); 107 }, 108 109 getWin : function() { 110 return window.dialogArguments || opener || parent || top; 111 }, 112 113 restoreSelection : function() { 114 var t = this; 115 116 if (tinymce.isIE) 117 t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark); 118 }, 119 120 setup : function() { 121 var t = this, a, ed = t.editor, g, columns, link, order, orderby; 122 if ( ! t.mcemode ) return; 123 124 t.restoreSelection(); 125 t.el = ed.selection.getNode(); 126 127 if ( t.el.nodeName != 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) { 128 if ( (g = ed.dom.select('img.wpGallery')) && g[0] ) { 129 t.el = g[0]; 130 } else { 131 if ( getUserSetting('galfile') == '1' ) t.I('linkto-file').checked = "checked"; 132 if ( getUserSetting('galdesc') == '1' ) t.I('order-desc').checked = "checked"; 133 if ( getUserSetting('galcols') ) t.I('columns').value = getUserSetting('galcols'); 134 if ( getUserSetting('galord') ) t.I('orderby').value = getUserSetting('galord'); 135 jQuery('#insert-gallery').show(); 136 return; 137 } 138 } 139 140 a = ed.dom.getAttrib(t.el, 'title'); 141 a = ed.dom.decode(a); 142 143 if ( a ) { 144 jQuery('#update-gallery').show(); 145 t.is_update = true; 146 147 columns = a.match(/columns=['"]([0-9]+)['"]/); 148 link = a.match(/link=['"]([^'"]+)['"]/i); 149 order = a.match(/order=['"]([^'"]+)['"]/i); 150 orderby = a.match(/orderby=['"]([^'"]+)['"]/i); 151 152 if ( link && link[1] ) t.I('linkto-file').checked = "checked"; 153 if ( order && order[1] ) t.I('order-desc').checked = "checked"; 154 if ( columns && columns[1] ) t.I('columns').value = ''+columns[1]; 155 if ( orderby && orderby[1] ) t.I('orderby').value = orderby[1]; 156 } else { 157 jQuery('#insert-gallery').show(); 158 } 159 }, 160 161 update : function() { 162 var t = this, ed = t.editor, all = '', s; 163 164 if ( ! t.mcemode || ! t.is_update ) { 165 s = '[gallery'+t.getSettings()+']'; 166 t.getWin().send_to_editor(s); 167 return; 168 } 169 170 if (t.el.nodeName != 'IMG') return; 171 172 all = ed.dom.decode(ed.dom.getAttrib(t.el, 'title')); 173 all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, ''); 174 all += t.getSettings(); 175 176 ed.dom.setAttrib(t.el, 'title', all); 177 t.getWin().tb_remove(); 178 }, 179 180 getSettings : function() { 181 var I = this.I, s = ''; 182 183 if ( I('linkto-file').checked ) { 184 s += ' link="file"'; 185 setUserSetting('galfile', '1'); 186 } 187 188 if ( I('order-desc').checked ) { 189 s += ' order="DESC"'; 190 setUserSetting('galdesc', '1'); 191 } 192 193 if ( I('columns').value != 3 ) { 194 s += ' columns="'+I('columns').value+'"'; 195 setUserSetting('galcols', I('columns').value); 196 } 197 198 if ( I('orderby').value != 'menu_order' ) { 199 s += ' orderby="'+I('orderby').value+'"'; 200 setUserSetting('galord', I('orderby').value); 201 } 202 203 return s; 204 } 205 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jan 8 00:19:48 2010 | Cross-referenced by PHPXref 0.7 |