--- wymeditor/wymeditor.module 2008-10-08 21:42:52.000000000 +0200 +++ wymeditor.ok/wymeditor.module 2008-11-09 16:01:10.000000000 +0100 @@ -13,11 +13,9 @@ function wymeditor_form_alter(&$form, $form_state, $form_id) { global $user; global $language; - // Check if the form has an input format selection group - $format_types = _wymeditor_input_format_alter($form); - - if ($key = array_search('WYMeditor', $format_types)) { + $format_infos = _wymeditor_input_format_alter($form); + if (isset($format_infos[0]['key'])) { $rids = array(); $filename = array(); if (count($user->roles) == 1) { @@ -73,7 +71,11 @@ } drupal_add_js($js_file); drupal_add_js($module_path .'/filters-format.js'); - drupal_add_js(array('wymeditor_key' => array($key), 'wymeditor_path' => array(url(drupal_get_path('module', 'wymeditor')))), 'setting'); + foreach($format_infos as $k => $tab) { + $t_key[] = $tab['key']; + $t_textarea[] = $tab['textarea']; + } + drupal_add_js(array('wymeditor_key' => $t_key,'wymeditor_area' => $t_textarea,'wymeditor_path' => array(url(drupal_get_path('module', 'wymeditor')))), 'setting'); } // Alter filter format @@ -142,36 +144,36 @@ * Helper; Alter the input format so it can be accessed by the jquery system */ function _wymeditor_input_format_alter(&$form) { - if ($format_types == NULL) { - static $format_types = array(); + if ($format_infos == NULL) { + static $format_infos = array(); } - if (is_array($form)) { foreach (element_children($form) as $key) { - if (is_array($form[$key]['format'])) { - // The common point for the filter system is the declaration of the function - // 'filter_form_validate' on the '#validate' atribute of Form API - if (is_array($form[$key]['format']['#element_validate']) && in_array('filter_form_validate', $form[$key]['format']['#element_validate'])) { - $form[$key]['format']['#attributes'] = array('class' => 'filter-formats'); - if (!$format_types) { - $formats = array(); - foreach ($form[$key]['format'] as $key => $e) { - if ($e['#type'] == 'radio' && $e['#parents'][0] == 'format') { - $formats[$key] = $e['#title']; + if(!isset($form[$key]['#type']) || ($form[$key]['#type']=='fieldset' && !isset($form[$key]['#element_validate']))) { + // This function is recursive to find all input formats groups + _wymeditor_input_format_alter(&$form[$key]); + } else { + if($form[$key]['#type']=='textarea') { + $textarea = $key; + } + else if ($form[$key]['#type']=='fieldset' && is_array($form[$key]['#element_validate']) + && in_array('filter_form_validate', $form[$key]['#element_validate'])) { + + $form[$key]['#attributes'] = array('class' => 'filter-formats'); + $format = array(); + foreach ($form[$key] as $a => $e) { + if ($e['#type'] == 'radio' && $e['#parents'][0] == $key && $e['#title'] == 'WYMeditor') { + $format['textarea'] = 'edit-'.str_replace('_','-',$textarea); + $format['key'] = $a; + $format_infos[]= $format; + } } } - $format_types = $formats; - } } - } - - // This function is recursive to find all input formats groups - _wymeditor_input_format_alter(&$form[$key]); - } + } } - - return $format_types; -} + return $format_infos; +} /** * Implementation of hook_nodeapi @@ -181,8 +183,9 @@ case 'presave': if ($node->files) { $path = file_directory_path(); - foreach ($node->files as $file) { - $node->body = str_replace(file_create_url(substr($file['filepath'], strrpos($file['filepath'], 'temp'))), file_create_url($path .'/'. $file['filename']), $node->body); + $files = $node->files; + foreach ($files as $file) { + $node->body = str_replace(file_create_url(substr($file->filepath, strrpos($file->filepath, 'temp'))), file_create_url($path .'/'. $file->filename), $node->body); } } break; @@ -419,6 +422,12 @@ + "",'; } + if (module_exists('imce')) { + $link = '+ "

" + + "IMCE" + + "

"'; + } + $filepath = file_directory_path() .'/js'; $module_path = drupal_get_path('module', 'wymeditor'); $js_file = $filepath .'/jquery.wymeditor.init.'. implode('-', $filename) .'.js'; @@ -431,8 +440,9 @@ .'dialogImageHtml: "" + "" - + "
" + + ">"' + .$link + .'+ "" + "
" + "{Image}" + "
" + "" - + "" + + "" + "
" + "
" + "" --- wymeditor/filters-format.js 2008-11-09 16:13:02.000000000 +0100 +++ wymeditor.ok/filters-format.js 2008-11-09 16:04:08.000000000 +0100 @@ -1,70 +1,89 @@ Drupal.filterFormatLoader = function() { - // prepare the new input formats scheme + // prepare the new input formats scheme $('.filter-formats .form-item input[@type=radio][@checked]').each( function() { - var filter_format = $(this).parents('.filter-formats');//.prevAll(":first"); - var form_item = $(filter_format).parent(); + var filter_format = $(this).parents('.filter-formats'); + var form_item = $(filter_format).parent(); var textareas = $(form_item).find('textarea'); - if (textareas[0].id=='edit-teaser-js') { - textarea = textareas[1]; - } else { - textarea = textareas[0]; + // find index and textarea + var index=-1; + for(i=0;i=0) + break; + for(j=0;j'+ $(legend).text() +''+ selected +'
'); - $(legend).remove(); - $(form_item).find('.filter-formats-box').append($(fieldset).children()); - $(form_item).find('.filter-formats-box').hide(); - $(fieldset).remove(); - - // initialize the WYMeditor if it is active - if ($(this).attr('value') == key) { - $(textarea).wymeditor($.wymeditor_config); - $(textarea).fadeOut(); - $(form_item).parent().find('.grippie').fadeOut(); + $(legend).remove(); + $(form_item).find('.filter-formats-box').append($(fieldset).children()); + $(form_item).find('.filter-formats-box').hide(); + $(fieldset).remove(); + + // initialize the WYMeditor if it is active + if ($(this).attr('value') == key) { + $(textarea).wymeditor($.wymeditor_config); + $(textarea).fadeOut(); + $(form_item).parent().find('.grippie').fadeOut(); } else { $(form_item).parent().find('.filter-formats').css('margin-right', $(form_item).find('.grippie').css('margin-right')); - } - }); + } + }); - // function to show/hide the new input formats box + // function to show/hide the new input formats box $('.filter-formats .link-open').click( function() { var filter_box = $(this).parents('div')[1]; - $(filter_box).find('.link-open').toggleClass('open'); - $(filter_box).find('.filter-formats-box').slideToggle('slow'); - return false; - }); + $(filter_box).find('.link-open').toggleClass('open'); + $(filter_box).find('.filter-formats-box').slideToggle('slow'); + return false; + }); // function to allow the change of the active editor $('.filter-formats-box .form-item input[@type=radio]').change( function() { - var form_item = $(this).parents('.filter-formats-box').parent(); - var textarea = $(form_item).find('textarea')[1]; - - var selected = $(this).parent().text(); - $(form_item).find('.active').html(selected); + var form_item = $(this).parents('.filter-formats-box').parent(); + var textareas = $(form_item).find('textarea'); + // find index and textarea + var index=-1; + for(i=0;i=0) + break; + for(j=0;j