コード例 #1
0
 /**
  * Registers required script for the plugin to work as DatePicker
  */
 public function registerClientScript()
 {
     $js_datepicker = [];
     $view = $this->getView();
     // @codeCoverageIgnoreStart
     if ($this->language !== null) {
         $this->clientOptions['language'] = $this->language;
         DatePickerMaskedWidgetLanguageAsset::register($view)->js[] = 'bootstrap-datepicker.' . $this->language . '.min.js';
     } else {
         DatePickerMaskedWidgetAsset::register($view);
     }
     // @codeCoverageIgnoreEnd
     $id = $this->options['id'];
     //the id of the element where to place the datepicker & inputmask
     $selector = ";jQuery('#{$id}')";
     if ($this->addon || $this->inline) {
         $selector .= ".parent()";
     }
     $options = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '';
     if ($this->inline) {
         $this->clientEvents['changeDate'] = "function (e){ jQuery('#{$id}').val(e.format());}";
     }
     $js_datepicker[] = "{$selector}.datepicker({$options});";
     if (!empty($this->clientEvents)) {
         foreach ($this->clientEvents as $event => $handler) {
             $js_datepicker[] = "{$selector}.on('{$event}', {$handler});";
         }
     }
     /* end of DatePicker registration */
     /*********************** maskedInput *************************/
     $js_mask = '';
     $view = $this->getView();
     $this->initMaskOptions();
     //MaskedInput
     if (!empty($this->mask)) {
         $this->maskOptions['mask'] = $this->mask;
     }
     $this->hashPluginOptions($view);
     if (is_array($this->definitions) && !empty($this->definitions)) {
         $js_mask .= '$.extend($.' . self::PLUGIN_NAME . '.defaults.definitions, ' . Json::htmlEncode($this->definitions) . ");\n";
     }
     if (is_array($this->aliases) && !empty($this->aliases)) {
         $js_mask .= '$.extend($.' . self::PLUGIN_NAME . '.defaults.aliases, ' . Json::htmlEncode($this->aliases) . ");\n";
     }
     $id2 = $this->options['id'];
     $js_mask .= '$("#' . $id2 . '").' . self::PLUGIN_NAME . "(" . $this->_hashVar . ");\n";
     /* end of maskedInput code*/
     /*********** end result for both **********/
     $js_datepicker = implode("\n", $js_datepicker);
     $js_result = $js_datepicker . $js_mask;
     $view->registerJS($js_result);
 }
 /**
  * Registers required script for the plugin to work as DateRangePicker
  */
 public function registerClientScript()
 {
     $js_datepicker = [];
     $view = $this->getView();
     // @codeCoverageIgnoreStart
     if ($this->language !== null) {
         $this->clientOptions['language'] = $this->language;
         DatePickerMaskedWidgetLanguageAsset::register($view)->js[] = 'bootstrap-datepicker.' . $this->language . '.min.js';
     } else {
         DateRangePickerMaskedWidgetAsset::register($view);
     }
     // @codeCoverageIgnoreEnd
     $id = $this->options['id'];
     $selector = ";jQuery('#{$id}').parent()";
     if ($this->form && $this->hasModel()) {
         // @codeCoverageIgnoreStart
         $selector .= '.parent()';
         $class = "field-" . Html::getInputId($this->model, $this->attribute);
         $js_datepicker[] = "{$selector}.closest('.{$class}').removeClass('{$class}');";
         // @codeCoverageIgnoreEnd
     }
     $options = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '';
     $js_datepicker[] = "{$selector}.datepicker({$options});";
     // @codeCoverageIgnoreStart
     if (!empty($this->clientEvents)) {
         foreach ($this->clientEvents as $event => $handler) {
             $js_datepicker[] = "{$selector}.on('{$event}', {$handler});";
         }
     }
     /*********************** maskedInput *************************/
     $js_mask = '';
     $view = $this->getView();
     $this->initMaskOptions();
     //MaskedInput
     if (!empty($this->mask)) {
         $this->maskOptions['mask'] = $this->mask;
     }
     $this->hashPluginOptions($view);
     if (is_array($this->definitions) && !empty($this->definitions)) {
         $js_mask .= '$.extend($.' . self::PLUGIN_NAME . '.defaults.definitions, ' . Json::htmlEncode($this->definitions) . ");\n";
     }
     if (is_array($this->aliases) && !empty($this->aliases)) {
         $js_mask .= '$.extend($.' . self::PLUGIN_NAME . '.defaults.aliases, ' . Json::htmlEncode($this->aliases) . ");\n";
     }
     $id2 = $this->options['id'];
     $js_mask .= '$("#' . $id2 . '").' . self::PLUGIN_NAME . "(" . $this->_hashVar . ");\n";
     $js_mask .= '$(".w1").' . self::PLUGIN_NAME . "(" . $this->_hashVar . ");\n";
     /* end of maskedInput code*/
     /*********** end result for both **********/
     $js_datepicker = implode("\n", $js_datepicker);
     $js_result = $js_datepicker . $js_mask;
     // @codeCoverageIgnoreEnd
     $view->registerJS($js_result);
 }