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