? imagecache.patch
Index: yui_editor.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/yui_editor/yui_editor.js,v
retrieving revision 1.1.2.17
diff -r1.1.2.17 yui_editor.js
38c38
<       yui_img_uploader(myEditor, '?q=/yui_editor/image_upload', 'files[upload]', config.base_path);
---
>       yui_img_uploader(myEditor, '/yui_editor/image_upload', 'files[upload]', config.base_path);
194a195
>             Dom.get('insertimage_url').STR_IMAGE_URL = "true";
197,199c198,226
<               '<input type="file" id="insertimage_upload" name="' + upload_image_name +
<               '" size="10" style="width: 20%"/>' +
<               '<a href="#"  id="insertimage_upload_btn" style="width: 20%; margin-left: 10em;">Upload Image</a>' +
---
>             '<input type="file" id="insertimage_upload" name="' + upload_image_name +
>             '" size="10" style="width: 20%"/>' +
>             '<a href="#"  id="insertimage_upload_btn" style="width: 20%; margin-left: 10em;">Upload Image</a>' +
>             '</label>';
>             var filesdir;
>             var presets;
>             jQuery.ajax({
>               type: "GET",
>               async: false,
>               url: "/yui_editor/imagecache",
>               dataType: "json",
>               success: function(data) {
>                 filesdir = data.filesdir;
>                 presets = data.presets;
>               }
>             });
>             console.log(filesdir);
>             var cachefiles = filesdir + '/imagecache/';
>             if(presets.length > 0){
>               //This section gives us the drop down to select the size we want.
>               var options = new Array();
>               jQuery.each(presets,function(i,n){
>                 options[i] = '<option value="' + n + '">' + n + '</option>';
>               });
>               var size_select = document.createElement('label');
>               size_select.innerHTML = '<strong>Image size:</strong>' +
>               '<select id="image_size">' +
>               options.join() +
>               '</select>' +
200a228
>             }
205c233,277
<                                                     
---
> 
>             //This section puts the size selector in place.
>             Dom.insertAfter(size_select, label);
> 
>             //Listener event for the size selector change
>             YAHOO.util.Event.on('image_size', 'change', function(ev) {
>               var currentUrl =  Dom.get('insertimage_url').value;
>               if (currentUrl != '') {
>                 //get new preset
>                 var imageCachePreset = Dom.get('image_size').value;
>                 //strip base file path
>                 var preset_end=currentUrl.indexOf('/imagecache/');
>                 var pathToImagecache = currentUrl.substring(0,preset_end+12);
>                 //strip old preset and add new one	
>                 var originalUrl = currentUrl.substring(preset_end+12);
>                 var slash_pos = originalUrl.indexOf('/');
>                 originalUrl = originalUrl.substring(slash_pos+1);
>                 newUrl = pathToImagecache + imageCachePreset + '/' + originalUrl;
> 
>                 // Start of code to update the url in rte image editor, 
>                 // and call imagecache to generate the new size if needed.
>                 // Code from yui documentation for YAHOO.util.Connect.asyncRequest
>                 var args = [newUrl];
>                 var responseSuccess = function(o){
>                   newUrl = o.argument;
>                   Dom.get('insertimage_upload').value = '';
>                   Dom.get('insertimage_url').value = newUrl;
>                   Dom.get('insertimage_url').focus();
>                   Dom.get('insertimage_upload').focus();
>                 };
>                 var responseFailure = function(o){
>                   alert("Could not get resized image, please try again.");
>                 }
>                 var imageCacheLoaded =
>                 {
>                   success:responseSuccess,
>                   failure:responseFailure,
>                   argument:args
>                 };
>                 //Get the new image from imagecache, then load in RTE to ensure imagecache has created the image
>                 var transaction = YAHOO.util.Connect.asyncRequest('GET', newUrl, imageCacheLoaded );
>               }
> 
>             });
> 
210c282
< 			    function(r) {
---
>                 function(r) {
215,218c287,324
<                       Dom.get('insertimage_upload').value = '';
<                       Dom.get('insertimage_url').value=base_path + o.image_url;
<                       Dom.get('insertimage_url').focus();
<                       Dom.get('insertimage_upload').focus();
---
>                       if (presets.length > 0) {
>                         console.log(presets);
>                         //Now the original image has been uploaded, alter the url to 
>                         //be the imagecache path for the size we want.
>                         var orginalUrl = base_path + o.image_url;
>                         var imageCachePreset = Dom.get('image_size').value;
>                         //Hard coded file path. Should replace this with variable, but how?
>                         var imageCacheInsert = cachefiles + imageCachePreset + '/';
>                         var newUrl = orginalUrl.replace(filesdir,imageCacheInsert);
>   
>                         // Start of code to update the url in rte image editor, 
>                         // and call imagecache to generate the new size if needed.
>                         // Code from yui documentation for YAHOO.util.Connect.asyncRequest
>                         var args = [newUrl];
>                         var responseSuccess = function(o){
>                           newUrl = o.argument;
>                           Dom.get('insertimage_upload').value = '';
>                           Dom.get('insertimage_url').value = newUrl;
>                           Dom.get('insertimage_url').focus();
>                           Dom.get('insertimage_upload').focus();
>                         };
>                         var responseFailure = function(o){
>                           alert("Could not upload image, please try again.");
>                         }
>                         var imageCacheLoaded =
>                         {
>                           success:responseSuccess,
>                           failure:responseFailure,
>                           argument:args
>                         };	
>                         //Get the new image from imagecache, then load in RTE to ensure imagecache has created the image
>                         var transaction = YAHOO.util.Connect.asyncRequest('GET', newUrl, imageCacheLoaded ); 
>                       } else {
>                         Dom.get('insertimage_upload').value = '';
>                         Dom.get('insertimage_url').value=base_path + o.image_url;
>                         Dom.get('insertimage_url').focus();
>                         Dom.get('insertimage_upload').focus();
>                       }
Index: yui_editor.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/yui_editor/yui_editor.module,v
retrieving revision 1.1.2.18
diff -r1.1.2.18 yui_editor.module
27a28,33
>     $items[] = array(
>       'path' => 'yui_editor/imagecache',
>       'callback' => 'yui_editor_imagecache',
>       'type' => MENU_CALLBACK,
>       'access' => user_access('access content')
>     );
221c227
<   $path .= 'images';
---
>   $path .= 'images/';
234a241,253
> 
> function yui_editor_imagecache() {
>   $presets = array();
>   $presets['filesdir'] = base_path().file_directory_path();
>   $presets['presets'] = array();
>   if (module_exists('imagecache')) {
>     $icpresets = imagecache_presets();
>     foreach($icpresets as $preset) {
>       array_push($presets['presets'], $preset['presetname']);
>     }
>   }
>   print drupal_to_js($presets);
> }
