Adding a no wordwrap option to img_assist

Note: this article is outdated now as the official Image Assist module now contains a no-word-wrap feature within it.

The Poorhouse's current favourite way of easily inserting images into Drupal nodes is to use the module img_assist. To use it, you also need to install the image module.

This gives you a decent user interface for people to upload and insert images into their Drupal nodes, with such basic formatting operations as alignment, size, and caption. By default you get a usually-pleasing word wrap type effect (via css floats) around the images when the page is finally rendered. However the Poorhouse wanted an option to not word wrap around the image, which isn't possible with the original module yet.

Due to usual lazy incompetence on the Poorhouse's part, it was done via a dirty hack. It relies on the fact that whatever you choose as alignment is rendered via the relevant style in the img_assist.css file. For instance, if you choose to left align, your image is surrounded by spans of class "left", defined as:

span.left {
  float: left;
  margin: 5px 5px 5px 0px;
}

The Poorhouse therefore invented a new span class called nowordwrap. Basically this rendered what would normally be an inline object as a block object as follows:

span.nowordwrap {
display: block;
}

All that then needed to be done was to make it easy for the user to select the non-word wrap option whilst using img_assist to put an image in.

In the img_assist.module file, you can find the following (on line 857 of the current CVS version):

'#options' => array('left'=>'left', 'right'=>'right'),

This is defining the options that the user is presented with amongst other things, so simply add the new option onto the list in the format 'spanclassname'=>'text the user sees'

'#options' => array('left'=>'left', 'right'=>'right', 'nowordwrap'=>'no wordwrap'),

...and you're done! As usual, much more should be done to make it perfect, but, it works good enough for us (tm). Whilst we used it to allow a no wordwrap option to exist you could add any sort of css based display options that can be cajoled into a CSS span tag.


Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <del> <p>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You may use [acidfree:xx] tags to display acidfree videos or images inline.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
8 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.