|
1 |
|
2 $.fn.realVal = function() { |
|
3 var obj = $(this[0]); |
|
4 if(obj.val) { |
|
5 if(obj.val() === obj.attr('defaultText')) { |
|
6 return ''; |
|
7 } |
|
8 else { |
|
9 return obj.val(); |
|
10 } |
|
11 } |
|
12 else { |
|
13 return null; |
|
14 } |
|
15 }; |
|
16 |
|
17 |
|
18 function init_events_base(base_node, embed_url) { |
|
19 |
|
20 $('.ldt_link_embed',base_node).click(function(e) { |
|
21 e.preventDefault(); |
|
22 var link = $(e.target); |
|
23 var json_url = link.attr("href"); |
|
24 var player_id = link.attr("id"); |
|
25 var ldt_id = player_id.substring(15); |
|
26 $('<a />', { |
|
27 href: embed_url+'?json_url='+escape(json_url)+'&player_id='+escape(player_id)+'&ldt_id='+escape(ldt_id), |
|
28 target: "_blank" |
|
29 }).nyroModal({ |
|
30 filters: ['iframe'], |
|
31 sizes: { |
|
32 minW: '750', |
|
33 minH: '662' |
|
34 }, |
|
35 callbacks: { |
|
36 afterShowCont: function(nm) { |
|
37 nm.store.iframe.height(662); |
|
38 nm.store.iframe.width(750); |
|
39 } |
|
40 } |
|
41 }).trigger('nyroModal'); |
|
42 return false; |
|
43 }); |
|
44 |
|
45 |
|
46 $('.imageline',base_node).each(function(i) { |
|
47 var tr = $(this); |
|
48 tr.mouseover(function() { |
|
49 $('.cellimgdiv',this).css('visibility', 'visible'); |
|
50 }); |
|
51 tr.mouseout(function() { |
|
52 $('.cellimgdiv',this).css('visibility', 'hidden'); |
|
53 }); |
|
54 }); |
|
55 |
|
56 $('.cellimgdiv img').qtip({ |
|
57 style: { |
|
58 'name': 'dark', |
|
59 'filter':'alpha(opacity=70)', |
|
60 '-moz-opacity':'0.7', |
|
61 '-khtml-opacity': '0.7', |
|
62 'opacity': '0.7', |
|
63 'border': { |
|
64 'width' : '0', |
|
65 'color': '#505050' |
|
66 }, |
|
67 'tip': true |
|
68 } |
|
69 }); |
|
70 } |
|
71 |
|
72 function testAndClose(close_fn) { |
|
73 |
|
74 return function(force) { |
|
75 // Here we ask LDT if the current work is modified and if the user want to save it. |
|
76 var ldtSwf = $('#ldtInitSwf',$.nmTop().store.iframe.contents()).get(0); |
|
77 // In the ldt_link_create case, the modal page can be the form, or the ldt swf. So we have to test. |
|
78 if (!force && ldtSwf && ldtSwf.name==="ldtInitSwf" && ldtSwf.isModified()==="true") { |
|
79 ldtSwf.askSave(); |
|
80 } |
|
81 else { |
|
82 close_fn.apply(this); |
|
83 } |
|
84 }; |
|
85 } |
|
86 |
|
87 |
|
88 function searchCallback(target, container_selector, url, timeout) { |
|
89 |
|
90 timeout = typeof(timeout) !== 'undefined' ? timeout : 0; |
|
91 target = $(target); |
|
92 |
|
93 // remove all qtip |
|
94 $(".qtip").remove(); |
|
95 |
|
96 if(target.realVal().length > 0) { |
|
97 target.nextAll(".searchclear").show(); |
|
98 } |
|
99 |
|
100 if(target.attr('timer')) { |
|
101 clearTimeout(target.attr('timer')); |
|
102 } |
|
103 |
|
104 target.attr( |
|
105 'timer', |
|
106 setTimeout(function() { |
|
107 target.next(".searchajaxloader").show(); |
|
108 target.nextAll(".searchclear").hide(); |
|
109 var filterVal = "_" + escape(target.realVal()); |
|
110 url = url.replace('__FILTER__',filterVal); |
|
111 $.ajax({ |
|
112 url: url, |
|
113 cache: false, |
|
114 success: function(data, status, request) { |
|
115 $(container_selector).html(data); |
|
116 target.next(".searchajaxloader").hide(); |
|
117 if(target.realVal().length > 0) { |
|
118 target.nextAll(".searchclear").show(); |
|
119 } |
|
120 init_events($(container_selector)); |
|
121 target.removeAttr('timer'); |
|
122 } |
|
123 }); |
|
124 }, |
|
125 300) |
|
126 ); |
|
127 } |
|
128 |
|
129 |
|
130 function init_events_contents(base_node, embed_url, content_filter_url) { |
|
131 |
|
132 init_events_base(base_node, embed_url); |
|
133 |
|
134 $('.content_link_create').each(function(i){ |
|
135 $(this).attr("target","_blank"); |
|
136 }); |
|
137 $('.content_link_create').nyroModal({ |
|
138 filters: ['iframe'], |
|
139 sizes: { |
|
140 minW: 770, |
|
141 minH: 550 |
|
142 }, |
|
143 callbacks: { |
|
144 afterClose: function(nm) { |
|
145 searchCallback($('#searchprojectsinput'), "#contentslistcontainer", content_filter_url); |
|
146 }, |
|
147 afterShowCont: function(nm) { |
|
148 nm.store.iframe.width(770); |
|
149 nm.store.iframe.height(550); |
|
150 nm.store.iframe.load(function() { |
|
151 var form_status = $(this).contents().find("#content_form_status").val(); |
|
152 if(form_status === 'saved' || form_status === 'deleted' ) { |
|
153 $.nmTop().close(); |
|
154 } |
|
155 }); |
|
156 } |
|
157 } |
|
158 }); |
|
159 |
|
160 $('.contenttitlelink').each(function(i){ |
|
161 $(this).attr("target","_blank"); |
|
162 }); |
|
163 $('.contenttitlelink').nyroModal({ |
|
164 filters: ['iframe'], |
|
165 sizes: { |
|
166 minW: 770, |
|
167 minH: 550 |
|
168 }, |
|
169 callbacks: { |
|
170 afterClose: function(nm) { |
|
171 searchCallback($("#searchcontentsinput"),"#contentslistcontainer",content_filter_url,0); |
|
172 }, |
|
173 afterShowCont: function(nm) { |
|
174 nm.store.iframe.width(770); |
|
175 nm.store.iframe.height(550); |
|
176 nm.store.iframe.load(function() { |
|
177 var form_status = $(this).contents().find("#content_form_status").val(); |
|
178 if(form_status === 'saved' || form_status === 'deleted') { |
|
179 $.nmTop().close(); |
|
180 } |
|
181 }); |
|
182 } |
|
183 } |
|
184 }); |
|
185 |
|
186 } |
|
187 |
|
188 function init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) { |
|
189 |
|
190 // These are the functions called when we display a project in an LDT modal window |
|
191 $('.ldt_link',base_node).each(function(i){ |
|
192 $(this).attr("target","_iri"); |
|
193 }); |
|
194 $('.ldt_link',base_node).nyroModal({ |
|
195 filters: ['iriIframe'], |
|
196 sizes: { |
|
197 minW: '1025', |
|
198 minH: '665' |
|
199 }, |
|
200 showCloseButton: true, |
|
201 closeOnEscape:false, |
|
202 closeOnClick:false, |
|
203 callbacks: { |
|
204 afterShowCont: function(nm) { |
|
205 nm.store.iframe.width(1025); |
|
206 nm.store.iframe.height(665); |
|
207 }, |
|
208 close: function(nm) { |
|
209 // We don't do anything here, we hack the callback directly from the close function. |
|
210 }, |
|
211 afterClose: function(nm) { |
|
212 // Can't do that because searchprojectfilterurl is not defined in init_events_base params |
|
213 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
|
214 } |
|
215 } |
|
216 }); |
|
217 |
|
218 |
|
219 $('.ldt_link',base_node).each(function(i, e) { |
|
220 nm = $(e).data('nmObj'); |
|
221 $(e).data('nmObj', $.extend(true, nm, { |
|
222 close: testAndClose(nm.close) |
|
223 })); |
|
224 }); |
|
225 |
|
226 |
|
227 $('.ldt_link_create',base_node).each(function(i){ |
|
228 $(this).attr("target","_iri"); |
|
229 }); |
|
230 $('.ldt_link_create',base_node).nyroModal({ |
|
231 |
|
232 filters: ['iriIframe'], |
|
233 sizes: { |
|
234 minW: '600', |
|
235 minH: '500' |
|
236 }, |
|
237 showCloseButton:true, |
|
238 closeOnEscape:false, |
|
239 closeOnClick:false, |
|
240 callbacks: { |
|
241 afterShowCont: function(nm) { |
|
242 nm.store.iframe.width(600); |
|
243 nm.store.iframe.height(600); |
|
244 var iframe = nm.store.iframe; |
|
245 iframe.load(function(){ |
|
246 var form_status = $(this).contents().find("#project_form_status").val(); |
|
247 if(form_status === 'saved' || form_status === 'deleted' ) { |
|
248 $.nmTop().close(); |
|
249 } |
|
250 var swfobject = $(this).contents().find("#ldtInitSwf"); |
|
251 if (swfobject.length) { |
|
252 nm['sizes']['initW'] = 1025; |
|
253 nm['sizes']['initH'] = 665; |
|
254 nm.resize(); |
|
255 nm.store.iframe.width(1025); |
|
256 nm.store.iframe.height(665); |
|
257 } |
|
258 }); |
|
259 }, |
|
260 afterClose: function(nm) { |
|
261 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
|
262 } |
|
263 } |
|
264 }); |
|
265 $('.ldt_link_create',base_node).each(function(i, e) { |
|
266 nm = $(e).data('nmObj'); |
|
267 $(e).data('nmObj', $.extend(true, nm, { |
|
268 close: testAndClose(nm.close) |
|
269 })); |
|
270 }); |
|
271 |
|
272 |
|
273 $('.publishedproject', base_node).click(function(e) { |
|
274 e.preventDefault(); |
|
275 var target = $(e.target); |
|
276 var project_id = target.attr('id').replace('project_',''); |
|
277 var url = unpublishprojecturl.replace('__PROJECT_ID__', project_id); |
|
278 $.ajax({ |
|
279 url: url, |
|
280 type: 'POST', |
|
281 dataType: 'json', |
|
282 success: function(json, textStatus, XMLHttpRequest){ |
|
283 if(json.res) { |
|
284 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
|
285 } |
|
286 } |
|
287 }); |
|
288 }); |
|
289 |
|
290 $('.unpublishedproject', base_node).click(function(e) { |
|
291 e.preventDefault(); |
|
292 var target = $(e.target); |
|
293 var project_id = target.attr('id').replace('project_',''); |
|
294 var url = publishprojecturl.replace('__PROJECT_ID__', project_id); |
|
295 $.ajax({ |
|
296 url: url, |
|
297 type: 'POST', |
|
298 dataType: 'json', |
|
299 success: function(json, textStatus, XMLHttpRequest){ |
|
300 if(json.res) { |
|
301 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
|
302 } |
|
303 } |
|
304 }); |
|
305 }); |
|
306 |
|
307 $('.projecttitlelink').each(function(i){ |
|
308 $(this).attr("target","_blank"); |
|
309 }); |
|
310 $('.projecttitlelink').nyroModal({ |
|
311 filters: ['iframe'], |
|
312 sizes: { |
|
313 minH:680, |
|
314 minW:600 |
|
315 }, |
|
316 callbacks: { |
|
317 afterClose: function(nm) { |
|
318 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
|
319 }, |
|
320 afterShowCont: function(nm) { |
|
321 nm.store.iframe.height(680); |
|
322 nm.store.iframe.width(600); |
|
323 var iframe = nm.store.iframe; |
|
324 iframe.load(function(){ |
|
325 var form_status = $(this).contents().find("#project_form_status").val(); |
|
326 if(form_status === 'saved' || form_status === 'deleted') { |
|
327 $.nmTop().close(); |
|
328 } |
|
329 }); |
|
330 } |
|
331 } |
|
332 }); |
|
333 |
|
334 } |
|
335 |
|
336 function init_events_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) { |
|
337 |
|
338 init_events_base(base_node, embed_url); |
|
339 init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl); |
|
340 } |
|
341 |
|
342 function init_events_all(base_node, embed_url, searchcontentfilterurl, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) { |
|
343 init_events_contents(base_node, embed_url, searchcontentfilterurl); |
|
344 init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl); |
|
345 } |
|
346 |
|
347 function searchFieldInit(input_list_init) { |
|
348 |
|
349 $(".searchfieldinputbase").keydown(function (e) { |
|
350 if(e.which === 27) { |
|
351 $(e.target).blur(); |
|
352 $(e.target).next(".searchajaxloader").hide(); |
|
353 } |
|
354 }); |
|
355 |
|
356 $('.searchfieldinput').each(function(i) { |
|
357 var sbox = $(this); |
|
358 if(sbox.val() !== '') { |
|
359 sbox.attr('defaultText', sbox.val()); |
|
360 } |
|
361 |
|
362 sbox.focus(function() { |
|
363 box = $(this); |
|
364 if(box.val() === box.attr('defaultText')) { |
|
365 box.val(''); |
|
366 box.toggleClass("searchfieldinput"); |
|
367 } |
|
368 }); |
|
369 |
|
370 sbox.blur(function() { |
|
371 var box = $(this); |
|
372 if(box.val() === '' && box.attr('defaultText')) { |
|
373 box.val(box.attr('defaultText')); |
|
374 box.toggleClass("searchfieldinput"); |
|
375 } |
|
376 }); |
|
377 |
|
378 }); |
|
379 |
|
380 $.each(input_list_init, function(index, value) { |
|
381 $(value['input_selector']).keyup(function (e) { |
|
382 searchCallback(e.target, value['container_selector'], value['url']); |
|
383 }); |
|
384 }); |
|
385 |
|
386 $('.searchclear').click(function(e) { |
|
387 var box = $(e.target).parent().find("input"); |
|
388 box.val(box.attr('defaultText')); |
|
389 box.addClass("searchfieldinput"); |
|
390 box.blur(); |
|
391 box.keyup(); |
|
392 }); |
|
393 |
|
394 $('.searchclear').each(function(i) { |
|
395 $(this).hide(); |
|
396 }); |
|
397 |
|
398 } |