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