UIX Documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • None
  • uix
    • data
    • ui
      • control

Classes

  • uix\data\data
  • uix\ui
  • uix\ui\box
  • uix\ui\control
  • uix\ui\control\autocomplete
  • uix\ui\control\button
  • uix\ui\control\checkbox
  • uix\ui\control\color
  • uix\ui\control\editor
  • uix\ui\control\email
  • uix\ui\control\file
  • uix\ui\control\hidden
  • uix\ui\control\number
  • uix\ui\control\post_relation
  • uix\ui\control\radio
  • uix\ui\control\select
  • uix\ui\control\separator
  • uix\ui\control\slider
  • uix\ui\control\template
  • uix\ui\control\text
  • uix\ui\control\textarea
  • uix\ui\control\toggle
  • uix\ui\footer
  • uix\ui\grid
  • uix\ui\header
  • uix\ui\help
  • uix\ui\metabox
  • uix\ui\modal
  • uix\ui\notice
  • uix\ui\page
  • uix\ui\panel
  • uix\ui\post_type
  • uix\ui\repeat
  • uix\ui\section
  • uix\ui\uix

Interfaces

  • uix\data\load
  • uix\data\save

Functions

  • uix
  • uix_autoload_class
  1 <?php
  2 /**
  3  * UIX Modal
  4  *
  5  * @package   ui
  6  * @author    David Cramer
  7  * @license   GPL-2.0+
  8  * @link
  9  * @copyright 2016 David Cramer
 10  */
 11 namespace uix\ui;
 12 
 13 /**
 14  * Same as the Box type, however it renders a button control that loads the modal via a template
 15  * 
 16  * @package uix\ui
 17  * @author  David Cramer
 18  */
 19 class modal extends panel{
 20 
 21     /**
 22      * The type of object
 23      *
 24      * @since 1.0.0
 25      * @access public
 26      * @var      string
 27      */
 28     public $type = 'modal';
 29 
 30     /**
 31      * footer object
 32      *
 33      * @since 1.0.0
 34      * @access public
 35      * @var      footer
 36      */
 37     public $footer;
 38 
 39     /**
 40      * modal template
 41      *
 42      * @since 1.0.0
 43      * @access public
 44      * @var      string
 45      */
 46     public $templates = null;
 47 
 48     /**
 49      * Sets the controls data
 50      *
 51      * @since 1.0.0
 52      * @see \uix\uix
 53      * @access public
 54      */
 55     public function init(){
 56         // run parents to setup sanitization filters
 57         parent::init();
 58         $data = uix()->request_vars('post');
 59         if (isset($data['uixNonce_' . $this->id()]) && wp_verify_nonce($data['uixNonce_' . $this->id()], $this->id())){
 60             wp_send_json_success( $this->get_data() );
 61         }
 62     }
 63         /**
 64      * Render the footer template
 65      *
 66      * @since 1.0.0
 67      * @see \uix\ui\uix
 68      * @access public
 69      * @return string HTML of rendered box
 70      */
 71     public function set_footers(){
 72         if( !empty( $this->child ) ){
 73             foreach ($this->child as $child_slug=>$child){
 74                 if ( in_array($child->type, array('footer') ) ){
 75                     $this->footer = $child;
 76                     $this->attributes['data-footer'] = '#' . $this->id() . '-footer-tmpl';
 77                 }
 78             }
 79         }
 80     }
 81     /**
 82      * Sets the wrappers attributes
 83      *
 84      * @since 1.0.0
 85      * @access public
 86      */
 87     public function set_attributes(){
 88 
 89         $this->attributes = array(
 90             'data-modal'    =>  $this->id(),
 91             'data-content'  =>  '#' . $this->id() . '-tmpl',
 92             'data-margin'   =>  12,
 93             'data-element'  =>  'form',
 94             'class'         =>  'button',
 95         );
 96 
 97         if( !empty( $this->struct['description'] ) ){
 98             $this->attributes['data-title'] = $this->struct['description'];
 99             unset( $this->struct['description'] );
100         }
101         if( !empty( $this->struct['attributes'] ) )
102             $this->attributes = array_merge( $this->attributes, $this->struct['attributes'] );
103 
104 
105     }
106 
107     /**
108      * Enqueues specific tabs assets for the active pages
109      *
110      * @since 1.0.0
111      * @access protected
112      */
113     protected function enqueue_active_assets(){
114         echo '<style>h3#' . $this->id() . '_uixModalLable { background: ' . $this->base_color() . '; }</style>';
115         parent::enqueue_active_assets();
116     }
117 
118     /**
119      * set assets
120      *
121      * @since 1.0.0
122      * @see \uix\ui\uix
123      * @access public
124      */
125     public function set_assets() {
126 
127         $this->assets['script']['modals'] = array(
128             'src' => $this->url . 'assets/js/modals' . UIX_ASSET_DEBUG . '.js',
129             'deps' => array( 'baldrick' ),
130         );
131         $this->assets['style']['modals'] = $this->url . 'assets/css/modals' . UIX_ASSET_DEBUG . '.css';
132 
133         parent::set_assets();
134     }
135 
136 
137     /**
138      * Render the Control
139      *
140      * @since 1.0.0
141      * @see \uix\ui\uix
142      * @access public
143      * @return string HTML of rendered box
144      */
145     public function render(){
146 
147         $this->set_footers();
148 
149         add_action( 'admin_footer', array( $this, 'output_templates' ) );
150         add_action( 'wp_footer', array( $this, 'output_templates' ) );
151 
152         $output = '<button ' . $this->build_attributes() . '>' . $this->struct['label'] . '</button>';
153 
154         $this->templates .= $this->render_modal_template();
155 
156         return $output;
157     }
158 
159     /**
160      * Render the Control
161      *
162      * @since 1.0.0
163      * @see \uix\ui\uix
164      * @access public
165      * @return string HTML of rendered box
166      */
167     public function render_modal_template(){
168         unset( $this->struct['label'] );
169         $output = '<script type="text/html" id="' . esc_attr( $this->id() ) . '-tmpl">';
170         $output .= parent::render();
171         $output .= '</script>';
172         $output .= $this->render_footer_template();
173         return $output;
174     }
175 
176 
177     /**
178      * Render the footer template
179      *
180      * @since 1.0.0
181      * @see \uix\ui\uix
182      * @access public
183      * @return string HTML of rendered box
184      */
185     public function render_footer_template(){
186         $output = null;
187         if ( !empty( $this->footer ) ){
188             $output .= '<script type="text/html" id="' . esc_attr( $this->id() ) . '-footer-tmpl">';
189             $output .= $this->footer->render();
190             $output .= '</script>';
191         }
192 
193         return $output;
194     }
195 
196     /**
197      * Render templates to page
198      *
199      * @since 1.0.0
200      * @see \uix\ui\uix
201      * @access public
202      * @return string HTML of rendered box
203      */
204     public function output_templates(){
205         echo $this->templates;
206     }
207 
208 }
UIX Documentation API documentation generated by ApiGen