VirtualPage::bindEvent PHP Method

bindEvent() public method

Bind owner's event (click by default) to a JavaScript chain which would open a new frame (or dialog, depending on $type property), and execute associated code inside it.
public bindEvent ( string $title = '', string $event = 'click', string $selector = null )
$title string Title of the frame
$event string JavaScript event
$selector string Not all parent will respond to click but only a selector
    public function bindEvent($title = '', $event = 'click', $selector = null)
    {
        $t = $this->type;
        if (is_null($event)) {
            $event = 'click';
        }
        $this->owner->on($event, $selector)->univ()->{$t}($title, $this->getURL(), $this->frame_options);
        return $this;
    }

Usage Example

Example #1
0
File: Button.php Project: atk4/atk4
 /**
  * Add click handler on button, that will execute callback. Similar to
  * onClick, however output from callback execution will appear in a
  * dialog window with a console.
  *
  * @param callable $callback
  * @param string $title
  */
 public function onClickConsole($callback, $title = null)
 {
     if (is_null($title)) {
         $title = $this->template->get('Content');
     }
     $this->virtual_page = $this->add('VirtualPage', ['type' => 'frameURL']);
     /** @type VirtualPage $this->virtual_page */
     $this->virtual_page->bindEvent($title)->set(function ($p) use($callback) {
         /** @type View_Console $console */
         $console = $p->add('View_Console');
         $console->set($callback);
     });
 }