hi there,

i'm new to nicedit and was glad to find a lightweight rte for drupal 6. i installed the module following the install instructions (just copied the module-source into /modules and downloaded the editor itself into /modules/nicedit/nicEditor).
The only thing that appeared now was the three links ("show html"...). I had a closer look into the page source now and found that that nicEdit.js was not included into the page head (and not in the footer).

After looking around for some time i found out, that the hook_footer does not work properly when using drupal_add_js() in it. When printing out the JS-code directly, the editor works as expected.

I changed the function into that:

function nicedit_footer() {
  global $base_path;
  if ($textareas = _nicedit_set_textarea()) {
    // include the nicEdit.js
    $path = drupal_get_path('module', 'nicedit') .'/nicEditor';
    if (file_exists(realpath($path .'/nicEdit.js'))) {
      $output = '<script type="text/javascript" src="'.$base_path.'/'.$path.'/nicEdit.js"></script>';
    }
    else {
      $output = '<script type="text/javascript" src="http://js.nicedit.com/nicEdit.js"></script>';
      unset($path);
    }

    // write the javascript to create each editor object on each textarea
    /**
     * HELP: saving the nicEditor with the jquery element isn't working.
     *  This needs to be done so that we can reference it in nicedit-enable.js
     *  so we can update the values when switching between html and the editor.
     */
    $js = array();
    $page = $_GET['q'];
    foreach ($textareas as $element_id) {
      $name = substr($element_id, strpos($element_id, '-') + 1);
      $all_settings = _nicedit_get_js_settings($page, $name, $path);
      $js[] = 'try { $(\''. $element_id .'\').nicedit = new nicEditor({'. $all_settings .'}).panelInstance(\''. $element_id .'\') } catch(err) { }';
    }
    $output .= '<script type="text/javascript">bkLib.onDomLoaded(function() {'. implode(';', $js) .'})</script>';

    return $output;
  }
}

this code isn't tested far, but works for my installation. maybe it's useful for creating a clean workaround.
bye
schneck

CommentFileSizeAuthor
#2 nicedit.patch1.09 KBSchneck

Comments

douggreen’s picture

Thanks! But can you create a patch file, it's hard to tell what you changed - see Creating patches.

Schneck’s picture

Status: Active » Needs review
StatusFileSize
new1.09 KB

ok then, here's the patch. hope it works as expected.

jaimerod’s picture

instead of $base_path, use $base_url. So try

function nicedit_footer() {


  // *** ADD THIS LINE ***
  global $base_url;


  if ($textareas = _nicedit_set_textarea()) {
    // include the nicEdit.js
    $path = drupal_get_path('module', 'nicedit') .'/nicEditor';
    if (file_exists(realpath($path .'/nicEdit.js'))) {


	  // *** Comment Out This Line ***
          //drupal_add_js($path .'/nicEdit.js', 'module'); 
	  // *** ADD THIS LINE ***
      $output = '<script type="text/javascript" src ="' . $base_url . "/" . $path . '/nicEdit.js"></script>'; 


    }
    else {
      $output = '<script type="text/javascript" src="http://js.nicedit.com/nicEdit.js"></script>';
      unset($path);
    }

    // write the javascript to create each editor object on each textarea
    /**
     * HELP: saving the nicEditor with the jquery element isn't working.
     *  This needs to be done so that we can reference it in nicedit-enable.js
     *  so we can update the values when switching between html and the editor.
     */
    $js = array();
    $page = $_GET['q'];
    foreach ($textareas as $element_id) {
      $name = substr($element_id, strpos($element_id, '-') + 1);
      $all_settings = _nicedit_get_js_settings($page, $name, $path);
      $js[] = 'try { $(\''. $element_id .'\').nicedit = new nicEditor({'. $all_settings .'}).panelInstance(\''. $element_id .'\') } catch(err) { }';
    }
    drupal_add_js('bkLib.onDomLoaded(function() {'. implode(';', $js) .'})', 'inline', isset($output) ? 'footer' : 'header');

    return $output;
  }
}

Notice how I spaced out the changed code and I put comments on the changes that I made.

douggreen’s picture

Status: Needs review » Closed (won't fix)