Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/uikit/modal/modal.php
<?php

class AnUikitModal extends AnUikitViewUikit
{
	/**
	 * buttons for array
	 * 
	 * @var array
	 */	
	public    $buttons = array();
	
	/**
	 * show cancel button for the modal when the open() method is called
	 * 
	 * @var bool
	 */
	public 	  $cancel_button = null;
	
	/**
	 * 
	 * @return 
	 * @param $options Object
	 */
	public function __construct($options)
	{
		parent::__construct($options);
		$this->setTitle('');
		$this->setBody('');
		$this->cancel_button = JText::_('CANCEL');
	}
	
	/**
	 * To start capturing the body of the modal, an alternative to setBody with a string
	 * @see setBody
	 */	
	public function startBody()
	{
		ob_start();	
	}
	
	/**
	 * End capturing the body of the modal
	 *
	 * @return AnUikitModal
	 */
	public function endBody()
	{
		$body = ob_get_contents();
		ob_clean();
		$this->setBody( $body );
		return $this;
	}
	
	/**
	 * Set the title of the modal
	 * @return AnUikitModal
	 * @param $title string
	 */
	public function setTitle($title)
	{
		$this->assign('title', $title);
		return $this;		
	}
	
	/**
	 * Set the body of the modal with a string.
	 * @return AnUikitModal
	 * @param $body string
	 */
	public function setBody($body)
	{
		$this->assign('body', $body);
		return $this;
	}
	
	/**
	 * Add buttons to the modal. The buttons are html tag button with attributes passed in as the option parameter
	 * @return AnUikitModal
	 * @param $name string
	 * @param $options array[optional]
	 */
	public function addButton($name, $options=array())
	{
		if ( !is_array($options) )	$options = array('id'=>$options);
		$this->buttons[] = AnUikitHtmlTag::tag('button', $name, $options);
		return $this;
	}
	
	/**
	 * Set the cancel button title on the modal. This only works if the modal is being opened through the open() method
	 * If label is set to false or null, the cancel button will not show
	 * @return AnUikitModal
	 * @param $label mixed
	 */
	public function setCancelButtonLabel($label)
	{
		$this->cancel_button = $label;
		return $this;
	}
	
	/**
	 * Return esacped string
	 * 
	 * @return string
	 */
	public function toString()
	{
		$html   = (string) $this;
		$html   = str_replace("\n",'',addslashes($html));
		return $html;
	}
		
	/**
	 * Instantly open the modal. It uses an inline javascript to open a modal with the contents set. A modal can 
	 * be opened also throuh the remote javascript, in the case this view is only used to build  the modal
	 *
	 */
	public function open()
	{		
		$html   = str_replace("\n",'',addslashes((string) $this));
		$label  = $this->cancel_button ? "'".$this->cancel_button."'" : 'false';
		print '<script>
					Uikit.Modal({
						html   : \''.$html.'\' ,
						uiOptions : {
							dismiss : '.$label.'
						}
					});
			  </script>
		';		
	}
}
Return current item: Anahita Social Engine