author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 19 Dec 2012 12:35:13 -0800 | |
changeset 203 | f507feede89a |
parent 194 | 32102edaa81b |
permissions | -rw-r--r-- |
136 | 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(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
$('img.pinkynail').toggle(false); |
136 | 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(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
51 |
$('img.pinkynail').toggle(true); |
136 | 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 |
}; |