[dokuwiki] best way to determine insert position for element?

  • From: "Getz, Robin" <robin.getz@xxxxxxxxxx>
  • To: "dokuwiki@xxxxxxxxxxxxx" <dokuwiki@xxxxxxxxxxxxx>
  • Date: Fri, 9 Dec 2011 13:02:58 -0500

The publish plugin
https://github.com/cosmocode/dokuwiki-plugin-publish/blob/master/action.php

includes code like:

$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this,
                                 handle_html_editform_output, array());

function handle_html_editform_output(&$event, $param) {
 [[snip]]
 $html = '<label class="nowrap" for="approved">
            <input
               type="checkbox"
               id="approved"
               name="approved"
               value="1"
               tabindex=3
               onclick="{ return approval_checkbox(\'' .
                                $this->getConf('apr_approved_text') . '\'); }"
            /> 
            <span>' . $this->getLang('apr_do_approve') . '</span>
          </label>';
  
  $event->data->insertElement(12,$html); //FIXME hardcoded element position
}

Obviously - that's a little fragile - any tweaks to the edit form, and this 
will break (which is what happens when you install any of the WYSIWYG 
editors). What's the best way to do things?

I assume, it would be to do use findElementById('edit__summary')?

I assume that's a constant name (and not changed between versions)?

Although, that's not really what is done today -- but I don't think there is 
any way to find the last element in the editButtons class - is there?

I guess findElementById('editButtons') and then walk forward via 
getElementAt(), until the closeTag('div') is found, and back up one?

Thanks
-Robin

-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: