1 jQuery(document).ready(function(c){var b,e,a,d=false;e=function(){b=c("#media-items").sortable({items:"div.media-item",placeholder:"sorthelper",axis:"y",distance:2,handle:"div.filename",stop:function(i,h){var g=c("#media-items").sortable("toArray"),f=g.length;c.each(g,function(k,l){var j=d?(f-k):(1+k);c("#"+l+" .menu_order input").val(j)})}})};sortIt=function(){var g=c(".menu_order_input"),f=g.length;g.each(function(j){var h=d?(f-j):(1+j);c(this).val(h)})};clearAll=function(f){f=f||0;c(".menu_order_input").each(function(){if(this.value=="0"||f){this.value=""}})};c("#asc").click(function(){d=false;sortIt();return false});c("#desc").click(function(){d=true;sortIt();return false});c("#clear").click(function(){clearAll(1);return false});c("#showall").click(function(){c("#sort-buttons span a").toggle();c("a.describe-toggle-on").hide();c("a.describe-toggle-off, table.slidetoggle").show();c("img.pinkynail").toggle(false);return false});c("#hideall").click(function(){c("#sort-buttons span a").toggle();c("a.describe-toggle-on").show();c("a.describe-toggle-off, table.slidetoggle").hide();c("img.pinkynail").toggle(true);return false});e();clearAll();if(c("#media-items>*").length>1){a=wpgallery.getWin();c("#save-all, #gallery-settings").show();if(typeof a.tinyMCE!="undefined"&&a.tinyMCE.activeEditor&&!a.tinyMCE.activeEditor.isHidden()){wpgallery.mcemode=true;wpgallery.init()}else{c("#insert-gallery").show()}}});jQuery(window).unload(function(){tinymce=tinyMCE=wpgallery=null});var tinymce=null,tinyMCE,wpgallery;wpgallery={mcemode:false,editor:{},dom:{},is_update:false,el:{},I:function(a){return document.getElementById(a)},init:function(){var d=this,a,f,c,e,b=d.getWin();if(!d.mcemode){return}a=(""+document.location.search).replace(/^\?/,"").split("&");f={};for(c=0;c<a.length;c++){e=a[c].split("=");f[unescape(e[0])]=unescape(e[1])}if(f.mce_rdomain){document.domain=f.mce_rdomain}tinymce=b.tinymce;tinyMCE=b.tinyMCE;d.editor=tinymce.EditorManager.activeEditor;d.setup()},getWin:function(){return window.dialogArguments||opener||parent||top},setup:function(){var f=this,c,d=f.editor,i,e,h,b,j;if(!f.mcemode){return}f.el=d.selection.getNode();if(f.el.nodeName!="IMG"||!d.dom.hasClass(f.el,"wpGallery")){if((i=d.dom.select("img.wpGallery"))&&i[0]){f.el=i[0]}else{if(getUserSetting("galfile")=="1"){f.I("linkto-file").checked="checked"}if(getUserSetting("galdesc")=="1"){f.I("order-desc").checked="checked"}if(getUserSetting("galcols")){f.I("columns").value=getUserSetting("galcols")}if(getUserSetting("galord")){f.I("orderby").value=getUserSetting("galord")}jQuery("#insert-gallery").show();return}}c=d.dom.getAttrib(f.el,"title");c=d.dom.decode(c);if(c){jQuery("#update-gallery").show();f.is_update=true;e=c.match(/columns=['"]([0-9]+)['"]/);h=c.match(/link=['"]([^'"]+)['"]/i);b=c.match(/order=['"]([^'"]+)['"]/i);j=c.match(/orderby=['"]([^'"]+)['"]/i);if(h&&h[1]){f.I("linkto-file").checked="checked"}if(b&&b[1]){f.I("order-desc").checked="checked"}if(e&&e[1]){f.I("columns").value=""+e[1]}if(j&&j[1]){f.I("orderby").value=j[1]}}else{jQuery("#insert-gallery").show()}},update:function(){var b=this,a=b.editor,d="",c;if(!b.mcemode||!b.is_update){c="[gallery"+b.getSettings()+"]";b.getWin().send_to_editor(c);return}if(b.el.nodeName!="IMG"){return}d=a.dom.decode(a.dom.getAttrib(b.el,"title"));d=d.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi,"");d+=b.getSettings();a.dom.setAttrib(b.el,"title",d);b.getWin().tb_remove()},getSettings:function(){var a=this.I,b="";if(a("linkto-file").checked){b+=' link="file"';setUserSetting("galfile","1")}if(a("order-desc").checked){b+=' order="DESC"';setUserSetting("galdesc","1")}if(a("columns").value!=3){b+=' columns="'+a("columns").value+'"';setUserSetting("galcols",a("columns").value)}if(a("orderby").value!="menu_order"){b+=' orderby="'+a("orderby").value+'"';setUserSetting("galord",a("orderby").value)}return b}}; |
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 $('img.pinkynail').toggle(false); |
|
45 return false; |
|
46 }); |
|
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); |
|
52 return false; |
|
53 }); |
|
54 |
|
55 // initialize sortable |
|
56 gallerySortableInit(); |
|
57 clearAll(); |
|
58 |
|
59 if ( $('#media-items>*').length > 1 ) { |
|
60 w = wpgallery.getWin(); |
|
61 |
|
62 $('#save-all, #gallery-settings').show(); |
|
63 if ( typeof w.tinyMCE != 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) { |
|
64 wpgallery.mcemode = true; |
|
65 wpgallery.init(); |
|
66 } else { |
|
67 $('#insert-gallery').show(); |
|
68 } |
|
69 } |
|
70 }); |
|
71 |
|
72 jQuery(window).unload( function () { tinymce = tinyMCE = wpgallery = null; } ); // Cleanup |
|
73 |
|
74 /* gallery settings */ |
|
75 var tinymce = null, tinyMCE, wpgallery; |
|
76 |
|
77 wpgallery = { |
|
78 mcemode : false, |
|
79 editor : {}, |
|
80 dom : {}, |
|
81 is_update : false, |
|
82 el : {}, |
|
83 |
|
84 I : function(e) { |
|
85 return document.getElementById(e); |
|
86 }, |
|
87 |
|
88 init: function() { |
|
89 var t = this, li, q, i, it, w = t.getWin(); |
|
90 |
|
91 if ( ! t.mcemode ) return; |
|
92 |
|
93 li = ('' + document.location.search).replace(/^\?/, '').split('&'); |
|
94 q = {}; |
|
95 for (i=0; i<li.length; i++) { |
|
96 it = li[i].split('='); |
|
97 q[unescape(it[0])] = unescape(it[1]); |
|
98 } |
|
99 |
|
100 if (q.mce_rdomain) |
|
101 document.domain = q.mce_rdomain; |
|
102 |
|
103 // Find window & API |
|
104 tinymce = w.tinymce; |
|
105 tinyMCE = w.tinyMCE; |
|
106 t.editor = tinymce.EditorManager.activeEditor; |
|
107 |
|
108 t.setup(); |
|
109 }, |
|
110 |
|
111 getWin : function() { |
|
112 return window.dialogArguments || opener || parent || top; |
|
113 }, |
|
114 |
|
115 setup : function() { |
|
116 var t = this, a, ed = t.editor, g, columns, link, order, orderby; |
|
117 if ( ! t.mcemode ) return; |
|
118 |
|
119 t.el = ed.selection.getNode(); |
|
120 |
|
121 if ( t.el.nodeName != 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) { |
|
122 if ( (g = ed.dom.select('img.wpGallery')) && g[0] ) { |
|
123 t.el = g[0]; |
|
124 } 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(); |
|
130 return; |
|
131 } |
|
132 } |
|
133 |
|
134 a = ed.dom.getAttrib(t.el, 'title'); |
|
135 a = ed.dom.decode(a); |
|
136 |
|
137 if ( a ) { |
|
138 jQuery('#update-gallery').show(); |
|
139 t.is_update = true; |
|
140 |
|
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); |
|
145 |
|
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]; |
|
150 } else { |
|
151 jQuery('#insert-gallery').show(); |
|
152 } |
|
153 }, |
|
154 |
|
155 update : function() { |
|
156 var t = this, ed = t.editor, all = '', s; |
|
157 |
|
158 if ( ! t.mcemode || ! t.is_update ) { |
|
159 s = '[gallery'+t.getSettings()+']'; |
|
160 t.getWin().send_to_editor(s); |
|
161 return; |
|
162 } |
|
163 |
|
164 if (t.el.nodeName != 'IMG') return; |
|
165 |
|
166 all = ed.dom.decode(ed.dom.getAttrib(t.el, 'title')); |
|
167 all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, ''); |
|
168 all += t.getSettings(); |
|
169 |
|
170 ed.dom.setAttrib(t.el, 'title', all); |
|
171 t.getWin().tb_remove(); |
|
172 }, |
|
173 |
|
174 getSettings : function() { |
|
175 var I = this.I, s = ''; |
|
176 |
|
177 if ( I('linkto-file').checked ) { |
|
178 s += ' link="file"'; |
|
179 setUserSetting('galfile', '1'); |
|
180 } |
|
181 |
|
182 if ( I('order-desc').checked ) { |
|
183 s += ' order="DESC"'; |
|
184 setUserSetting('galdesc', '1'); |
|
185 } |
|
186 |
|
187 if ( I('columns').value != 3 ) { |
|
188 s += ' columns="'+I('columns').value+'"'; |
|
189 setUserSetting('galcols', I('columns').value); |
|
190 } |
|
191 |
|
192 if ( I('orderby').value != 'menu_order' ) { |
|
193 s += ' orderby="'+I('orderby').value+'"'; |
|
194 setUserSetting('galord', I('orderby').value); |
|
195 } |
|
196 |
|
197 return s; |
|
198 } |
|
199 }; |