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