Source for file media.php
Documentation is available at media.php
* @package Joomla.Libraries
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Form Field class for the Joomla CMS.
* Provides a modal media selector including upload mechanism
* @package Joomla.Libraries
protected $type =
'Media';
* The initialised state of the document object.
protected static $initialised =
false;
* Method to get certain otherwise inaccessible properties from the form field object.
* @param string $name The property name for which to the the value.
* @return mixed The property value or null.
public function __get($name)
return parent::__get($name);
* Method to set certain otherwise inaccessible properties of the form field object.
* @param string $name The property name for which to the the value.
* @param mixed $value The value of the property.
public function __set($name, $value)
$this->$name = (string)
$value;
$this->$name = (int)
$value;
parent::__set($name, $value);
* Method to attach a JForm object to the field.
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @return boolean True on success.
* @see JFormField::setup()
public function setup(SimpleXMLElement $element, $value, $group =
null)
$result =
parent::setup($element, $value, $group);
$assetField =
$this->element['asset_field'] ? (string)
$this->element['asset_field'] :
'asset_id';
$this->asset =
$this->form->getValue($assetField) ?
$this->form->getValue($assetField) : (string)
$this->element['asset_id'];
* Method to get the field input markup for a media selector.
* Use attributes to identify specific created_by and asset_id fields
* @return string The field input markup.
// Load the modal behavior script.
JHtml::_('behavior.modal');
$script[] =
' function jInsertFieldValue(value, id) {';
$script[] =
' var old_value = document.id(id).value;';
$script[] =
' if (old_value != value) {';
$script[] =
' var elem = document.id(id);';
$script[] =
' elem.value = value;';
$script[] =
' elem.fireEvent("change");';
$script[] =
' if (typeof(elem.onchange) === "function") {';
$script[] =
' elem.onchange();';
$script[] =
' jMediaRefreshPreview(id);';
$script[] =
' function jMediaRefreshPreview(id) {';
$script[] =
' var value = document.id(id).value;';
$script[] =
' var img = document.id(id + "_preview");';
$script[] =
' if (img) {';
$script[] =
' if (value) {';
$script[] =
' img.src = "' .
JUri::root() .
'" + value;';
$script[] =
' document.id(id + "_preview_empty").setStyle("display", "none");';
$script[] =
' document.id(id + "_preview_img").setStyle("display", "");';
$script[] =
' } else { ';
$script[] =
' img.src = ""';
$script[] =
' document.id(id + "_preview_empty").setStyle("display", "");';
$script[] =
' document.id(id + "_preview_img").setStyle("display", "none");';
$script[] =
' function jMediaRefreshPreviewTip(tip)';
$script[] =
' var img = tip.getElement("img.media-preview");';
$script[] =
' tip.getElement("div.tip").setStyle("max-width", "none");';
$script[] =
' var id = img.getProperty("id");';
$script[] =
' id = id.substring(0, id.length - "_preview".length);';
$script[] =
' jMediaRefreshPreview(id);';
$script[] =
' tip.setStyle("display", "block");';
// Add the script to the document head.
self::$initialised =
true;
// Initialize some field attributes.
$attr .=
!empty($this->class) ?
' class="input-small ' .
$this->class .
'"' :
'class="input-small"';
$attr .=
!empty($this->size) ?
' size="' .
$this->size .
'"' :
'';
// Initialize JavaScript field attributes.
$html[] =
'<div class="input-prepend input-append">';
case 'no':
// Deprecated parameter value
case 'yes':
// Deprecated parameter value
'onShow' =>
'jMediaRefreshPreviewTip',
JHtml::_('behavior.tooltip', '.hasTipPreview', $options);
$style .=
($width >
0) ?
'max-width:' .
$width .
'px;' :
'';
$style .=
($height >
0) ?
'max-height:' .
$height .
'px;' :
'';
'id' =>
$this->id .
'_preview',
'class' =>
'media-preview',
$img =
JHtml::image($src, JText::_('JLIB_FORM_MEDIA_PREVIEW_ALT'), $imgattr);
$previewImg =
'<div id="' .
$this->id .
'_preview_img"' .
($src ?
'' :
' style="display:none"') .
'>' .
$img .
'</div>';
$previewImgEmpty =
'<div id="' .
$this->id .
'_preview_empty"' .
($src ?
' style="display:none"' :
'') .
'>'
.
JText::_('JLIB_FORM_MEDIA_PREVIEW_EMPTY') .
'</div>';
$html[] =
'<div class="media-preview add-on">';
$tooltip =
$previewImgEmpty .
$previewImg;
'title' =>
JText::_('JLIB_FORM_MEDIA_PREVIEW_SELECTED_IMAGE'),
'text' =>
'<i class="icon-eye"></i>',
'class' =>
'hasTipPreview'
$html[] =
JHtml::tooltip($tooltip, $options);
$html[] =
'<div class="media-preview add-on" style="height:auto">';
$html[] =
' ' .
$previewImgEmpty;
$html[] =
' ' .
$previewImg;
$html[] =
' <input type="text" name="' .
$this->name .
'" id="' .
$this->id .
'" value="'
JHtml::_('bootstrap.tooltip');
$html[] =
'<a class="modal btn" title="' .
JText::_('JLIB_FORM_BUTTON_SELECT') .
'" href="'
:
'index.php?option=com_media&view=images&tmpl=component&asset=' .
$asset .
'&author='
.
$this->form->getValue($this->authorField)) .
'&fieldid=' .
$this->id .
'&folder=' .
$folder) .
'"'
.
' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
$html[] =
JText::_('JLIB_FORM_BUTTON_SELECT') .
'</a><a class="btn hasTooltip" title="' .
JText::_('JLIB_FORM_BUTTON_CLEAR') .
'" href="#" onclick="';
$html[] =
'jInsertFieldValue(\'\', \'' .
$this->id .
'\');';
$html[] =
'return false;';
$html[] =
'<i class="icon-remove"></i></a>';
Documentation generated on Tue, 19 Nov 2013 15:07:41 +0100 by phpDocumentor 1.4.3