| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 // $Id: imce_set_app.js,v 1.4.2.5 2010/12/12 07:23:33 ufku Exp $ 2 /* 3 * IMCE Integration by URL 4 * Ex-1: http://example.com/imce?app=XEditor|url@urlFieldId|width@widthFieldId|height@heightFieldId 5 * Creates "Insert file" operation tab, which fills the specified fields with url, width, height properties 6 * of the selected file in the parent window 7 * Ex-2: http://example.com/imce?app=XEditor|sendto@functionName 8 * "Insert file" operation calls parent window's functionName(file, imceWindow) 9 * Ex-3: http://example.com/imce?app=XEditor|imceload@functionName 10 * Parent window's functionName(imceWindow) is called as soon as IMCE UI is ready. Send to operation 11 * needs to be set manually. See imce.setSendTo() method in imce.js 12 */ 13 14 (function($) { 15 16 var appFields = {}, appWindow = (top.appiFrm||window).opener || parent; 17 18 // Execute when imce loads. 19 imce.hooks.load.push(function(win) { 20 var index = location.href.lastIndexOf('app='); 21 if (index == -1) return; 22 var data = decodeURIComponent(location.href.substr(index + 4)).split('|'); 23 var arr, prop, str, func, appName = data.shift(); 24 // Extract fields 25 for (var i = 0, len = data.length; i < len; i++) { 26 str = data[i]; 27 if (!str.length) continue; 28 if (str.indexOf('&') != -1) str = str.split('&')[0]; 29 arr = str.split('@'); 30 if (arr.length > 1) { 31 prop = arr.shift(); 32 appFields[prop] = arr.join('@'); 33 } 34 } 35 // Run custom onload function if available 36 if (appFields.imceload && (func = isFunc(appFields.imceload))) { 37 func(win); 38 delete appFields.imceload; 39 } 40 // Set custom sendto function. appFinish is the default. 41 var sendtoFunc = appFields.url ? appFinish : false; 42 //check sendto@funcName syntax in URL 43 if (appFields.sendto && (func = isFunc(appFields.sendto))) { 44 sendtoFunc = func; 45 delete appFields.sendto; 46 } 47 // Check old method windowname+ImceFinish. 48 else if (win.name && (func = isFunc(win.name +'ImceFinish'))) { 49 sendtoFunc = func; 50 } 51 // Highlight file 52 if (appFields.url) { 53 // Support multiple url fields url@field1,field2.. 54 if (appFields.url.indexOf(',') > -1) { 55 var arr = appFields.url.split(','); 56 for (var i in arr) { 57 if ($('#'+ arr[i], appWindow.document).size()) { 58 appFields.url = arr[i]; 59 break; 60 } 61 } 62 } 63 var filename = $('#'+ appFields.url, appWindow.document).val() || ''; 64 imce.highlight(filename.substr(filename.lastIndexOf('/')+1)); 65 } 66 // Set send to 67 sendtoFunc && imce.setSendTo(Drupal.t('Insert file'), sendtoFunc); 68 }); 69 70 // Default sendTo function 71 var appFinish = function(file, win) { 72 var $doc = $(appWindow.document); 73 for (var i in appFields) { 74 $doc.find('#'+ appFields[i]).val(file[i]); 75 } 76 if (appFields.url) { 77 try{ 78 $doc.find('#'+ appFields.url).blur().change().focus(); 79 }catch(e){ 80 try{ 81 $doc.find('#'+ appFields.url).trigger('onblur').trigger('onchange').trigger('onfocus');//inline events for IE 82 }catch(e){} 83 } 84 } 85 appWindow.focus(); 86 win.close(); 87 }; 88 89 // Checks if a string is a function name in the given scope. 90 // Returns function reference. Supports x.y.z notation. 91 var isFunc = function(str, scope) { 92 var obj = scope || appWindow; 93 var parts = str.split('.'), len = parts.length; 94 for (var i = 0; i < len && (obj = obj[parts[i]]); i++); 95 return obj && i == len && (typeof obj == 'function' || typeof obj != 'string' && !obj.nodeName && obj.constructor != Array && /^[\s[]?function/.test(obj.toString())) ? obj : false; 96 } 97 98 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |