API16

JHtmlBehavior/uploader

From Joomla! Documentation

< API16:JHtmlBehavior
Revision as of 21:56, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)

The "API16" 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.

[<! removed edit link to red link >]

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

Syntax[edit]

static uploader($id='file-upload', $params=array(), $upload_queue='upload-queue')
Parameter Name Default Value Description
$id 'file-upload'
$params array()
$upload_queue 'upload-queue'

Defined in[edit]

libraries/joomla/html/html/behavior.php

Importing[edit]

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

Source Body[edit]

public static function uploader($id='file-upload', $params = array(), $upload_queue='upload-queue')
{
        JHTML::_('script','system/swf.js', false, true);
        JHTML::_('script','system/progressbar.js', false, true);
        JHTML::_('script','system/uploader.js', false, true);

        static $uploaders;

        if (!isset($uploaders)) {
                $uploaders = array();
        }

        if (isset($uploaders[$id]) && ($uploaders[$id])) {
                return;
        }

        // Setup options object
        $opt['url']                                     = (isset($params['targetURL'])) ? $params['targetURL'] : null ;
        $opt['path']                            = (isset($params['swf'])) ? $params['swf'] : JURI::root(true).'/media/system/swf/uploader.swf';
        $opt['height']                          = (isset($params['height'])) && $params['height'] ? (int)$params['height'] : null;
        $opt['width']                           = (isset($params['width'])) && $params['width'] ? (int)$params['width'] : null;
        $opt['multiple']                        = (isset($params['multiple']) && !($params['multiple'])) ? '\\false' : '\\true';
        $opt['queued']                          = (isset($params['queued']) && !($params['queued'])) ? (int)$params['queued'] : null;
        $opt['target']                          = (isset($params['target'])) ? $params['target'] : '\\$(\'upload-browse\')';
        $opt['instantStart']            = (isset($params['instantStart']) && ($params['instantStart'])) ? '\\true' : '\\false';
        $opt['allowDuplicates']         = (isset($params['allowDuplicates']) && !($params['allowDuplicates'])) ? '\\false' : '\\true';
        // limitSize is the old parameter name.  Remove in 1.7
        $opt['fileSizeMax']                     = (isset($params['limitSize']) && ($params['limitSize'])) ? (int)$params['limitSize'] : null;
        // fileSizeMax is the new name.  If supplied, it will override the old value specified for limitSize
        $opt['fileSizeMax']                     = (isset($params['fileSizeMax']) && ($params['fileSizeMax'])) ? (int)$params['fileSizeMax'] : $opt['fileSizeMax'];
        $opt['fileSizeMin']                     = (isset($params['fileSizeMin']) && ($params['fileSizeMin'])) ? (int)$params['fileSizeMin'] : null;
        // limitFiles is the old parameter name.  Remove in 1.7
        $opt['fileListMax']                     = (isset($params['limitFiles']) && ($params['limitFiles'])) ? (int)$params['limitFiles'] : null;
        // fileListMax is the new name.  If supplied, it will override the old value specified for limitFiles
        $opt['fileListMax']                     = (isset($params['fileListMax']) && ($params['fileListMax'])) ? (int)$params['fileListMax'] : $opt['fileListMax'];
        $opt['fileListSizeMax']         = (isset($params['fileListSizeMax']) && ($params['fileListSizeMax'])) ? (int)$params['fileListSizeMax'] : null;
        // types is the old parameter name.  Remove in 1.7
        $opt['typeFilter']                      = (isset($params['types'])) ?'\\'.$params['types'] : '\\{\'All Files (*.*)\': \'*.*\'}';
        $opt['typeFilter']                      = (isset($params['typeFilter'])) ?'\\'.$params['typeFilter'] : $opt['typeFilter'];


        // Optional functions
        $opt['createReplacement'] = (isset($params['createReplacement'])) ? '\\'.$params['createReplacement'] : null;
        $opt['onFileComplete'] = (isset($params['onFileComplete'])) ? '\\'.$params['onFileComplete'] : null;
        $opt['onComplete'] = (isset($params['onComplete'])) ? '\\'.$params['onComplete'] : null;
        $opt['onFileSuccess'] = (isset($params['onFileSuccess'])) ? '\\'.$params['onFileSuccess'] : null;

        if(!isset($params['startButton'])) $params['startButton'] = 'upload-start';
        if(!isset($params['clearButton'])) $params['clearButton'] = 'upload-clear';

        $opt['onLoad'] =
                '\\function() {
                        document.id(\''.$id.'\').removeClass(\'hide\'); // we show the actual UI
                        document.id(\'upload-noflash\').destroy(); // ... and hide the plain form

                        // We relay the interactions with the overlayed flash to the link
                        this.target.addEvents({
                                click: function() {
                                        return false;
                                },
                                mouseenter: function() {
                                        this.addClass(\'hover\');
                                },
                                mouseleave: function() {
                                        this.removeClass(\'hover\');
                                        this.blur();
                                },
                                mousedown: function() {
                                        this.focus();
                                }
                        });

                        // Interactions for the 2 other buttons

                        document.id(\''.$params['clearButton'].'\').addEvent(\'click\', function() {
                                Uploader.remove(); // remove all files
                                return false;
                        });

                        document.id(\''.$params['startButton'].'\').addEvent(\'click\', function() {
                                Uploader.start(); // start upload
                                return false;
                        });
                }';

        $options = JHtmlBehavior::_getJSObject($opt);

        // Attach tooltips to document
        $document = &JFactory::getDocument();
        $uploaderInit =
                        'window.addEvent(\'domready\', function(){
                        var Uploader = new FancyUpload2($(\''.$id.'\'), $(\''.$upload_queue.'\'), '.$options.' );
                        });';
        $document->addScriptDeclaration($uploaderInit);

        // Set static array
        $uploaders[$id] = true;
        return;
}

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

Examples[edit]

<CodeExamplesForm />