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