|
1 // $Id: imce_set_app.js,v 1.3.2.6 2009/02/20 21:17:25 ufku Exp $ |
|
2 //When imce url contains &app=appName|fileProperty1@correspondingFieldId1|fileProperty2@correspondingFieldId2|... |
|
3 //the specified fields are filled with the specified properties of the selected file. |
|
4 |
|
5 var appFields = {}, appWindow = (top.appiFrm||window).opener; |
|
6 |
|
7 //execute when imce loads. |
|
8 imce.hooks.load.push(function(win) { |
|
9 var data = decodeURIComponent(location.href.substr(location.href.lastIndexOf('app=')+4)).split('|'); |
|
10 var appName = data.shift(); |
|
11 //extract fields |
|
12 for (var i in data) { |
|
13 var arr = data[i].split('@'); |
|
14 appFields[arr[0]] = arr[1]; |
|
15 } |
|
16 //run custom onload function if available. |
|
17 if (appFields['onload'] && $.isFunction(appWindow[appFields['onload']])) { |
|
18 appWindow[appFields['onload']](win); |
|
19 delete appFields['onload']; |
|
20 } |
|
21 //set custom sendto function. appFinish is the default. |
|
22 var sendtoFunc = appFields['url'] ? appFinish : false; |
|
23 //check sendto@funcName syntax in URL |
|
24 if (appFields['sendto'] && $.isFunction(appWindow[appFields['sendto']])) { |
|
25 sendtoFunc = appWindow[appFields['sendto']]; |
|
26 delete appFields['sendto']; |
|
27 } |
|
28 //check windowname+ImceFinish. old method |
|
29 else if (win.name && $.isFunction(appWindow[win.name +'ImceFinish'])) { |
|
30 sendtoFunc = appWindow[win.name +'ImceFinish']; |
|
31 } |
|
32 //highlight file |
|
33 if (appFields['url']) { |
|
34 if (appFields['url'].indexOf(',') > -1) {//support multiple url fields url@field1,field2.. |
|
35 var arr = appFields['url'].split(','); |
|
36 for (var i in arr) { |
|
37 if ($('#'+ arr[i], appWindow.document).size()) { |
|
38 appFields['url'] = arr[i]; |
|
39 break; |
|
40 } |
|
41 } |
|
42 } |
|
43 var filename = $('#'+ appFields['url'], appWindow.document).val(); |
|
44 imce.highlight(filename.substr(filename.lastIndexOf('/')+1)); |
|
45 } |
|
46 //set send to |
|
47 if (sendtoFunc) { |
|
48 imce.setSendTo(Drupal.t('Send to @app', {'@app': appName}), sendtoFunc); |
|
49 } |
|
50 }); |
|
51 |
|
52 //sendTo function |
|
53 var appFinish = function(file, win) { |
|
54 var doc = $(appWindow.document); |
|
55 for (var i in appFields) { |
|
56 doc.find('#'+ appFields[i]).val(file[i]); |
|
57 } |
|
58 if (appFields['url']) { |
|
59 try{doc.find('#'+ appFields['url']).blur().change().focus()}catch(e){}; |
|
60 try{doc.find('#'+ appFields['url']).trigger('onblur').trigger('onchange').trigger('onfocus')}catch(e){};//inline events |
|
61 } |
|
62 appWindow.focus(); |
|
63 win.close(); |
|
64 }; |