API15

JHTMLList/images

From Joomla! Documentation

< API15:JHTMLList

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Build the select list to choose an image

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

images($name, $active=NULL, $javascript=NULL, $directory=NULL, $extensions="bmp|gif|jpg|png")
Parameter Name Default Value Description
$name
$active NULL
$javascript NULL
$directory NULL
$extensions gif|jpg|png"

Defined in[edit]

libraries/joomla/html/html/list.php

Importing[edit]

jimport( 'joomla.html.html.list' );

Source Body[edit]

function images( $name, $active = NULL, $javascript = NULL, $directory = NULL, $extensions =  "bmp|gif|jpg|png" )
{
        if ( !$directory ) {
                $directory = '/images/stories/';
        }

        if ( !$javascript ) {
                $javascript = "onchange=\"javascript:if (document.forms.adminForm." . $name . ".options[selectedIndex].value!='') {document.imagelib.src='..$directory' + document.forms.adminForm." . $name . ".options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
        }

        jimport( 'joomla.filesystem.folder' );
        $imageFiles = JFolder::files( JPATH_SITE.DS.$directory );
        $images         = array(  JHTML::_('select.option',  '', '- '. JText::_( 'Select Image' ) .' -' ) );
        foreach ( $imageFiles as $file ) {
           if ( preg_match( "#$extensions#i", $file ) ) {
                        $images[] = JHTML::_('select.option',  $file );
                }
        }
        $images = JHTML::_('select.genericlist',  $images, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );

        return $images;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]