|
24 | 24 | use unclead\multipleinput\TabularInput; |
25 | 25 | use unclead\multipleinput\assets\MultipleInputAsset; |
26 | 26 | use unclead\multipleinput\assets\MultipleInputSortableAsset; |
27 | | -use unclead\multipleinput\components\JsCollector; |
28 | 27 | use unclead\multipleinput\components\BaseColumn; |
29 | 28 |
|
30 | 29 | /** |
@@ -356,35 +355,64 @@ protected function getExtraButtons($index, $item) |
356 | 355 | return $content; |
357 | 356 | } |
358 | 357 |
|
359 | | - /** |
360 | | - * @return mixed |
361 | | - * |
362 | | - * @throws InvalidConfigException |
363 | | - * @throws NotSupportedException |
364 | | - */ |
365 | 358 | public function render() |
366 | 359 | { |
367 | 360 | $this->initColumns(); |
368 | 361 |
|
369 | 362 | $view = $this->context->getView(); |
370 | 363 | MultipleInputAsset::register($view); |
371 | 364 |
|
372 | | - $jsCollector = new JsCollector($view); |
| 365 | + // Collect all js scripts which were added before rendering of our widget |
| 366 | + $jsBefore= []; |
| 367 | + if (is_array($view->js)) { |
| 368 | + foreach ($view->js as $position => $scripts) { |
| 369 | + foreach ((array)$scripts as $key => $js) { |
| 370 | + if (!isset($jsBefore[$position])) { |
| 371 | + $jsBefore[$position] = []; |
| 372 | + } |
| 373 | + $jsBefore[$position][$key] = $js; |
| 374 | + } |
| 375 | + } |
| 376 | + } |
373 | 377 |
|
374 | | - $jsCollector->onBeforeRender(); |
| 378 | + $content = $this->internalRender(); |
375 | 379 |
|
376 | | - $content = $this->internalRender(); |
377 | | - $jsCollector->onAfterRender(); |
| 380 | + // Collect all js scripts which has to be appended to page before initialization widget |
| 381 | + $jsInit = []; |
| 382 | + if (is_array($view->js)) { |
| 383 | + foreach ($this->jsPositions as $position) { |
| 384 | + foreach (ArrayHelper::getValue($view->js, $position, []) as $key => $js) { |
| 385 | + if (isset($jsBefore[$position][$key])) { |
| 386 | + continue; |
| 387 | + } |
| 388 | + $jsInit[$key] = $js; |
| 389 | + $jsBefore[$position][$key] = $js; |
| 390 | + unset($view->js[$position][$key]); |
| 391 | + } |
| 392 | + } |
| 393 | + } |
378 | 394 |
|
379 | 395 | $template = $this->prepareTemplate(); |
380 | | - $jsCollector->onAfterPrepareTemplate(); |
| 396 | + |
| 397 | + $jsTemplates = []; |
| 398 | + if (is_array($view->js)) { |
| 399 | + foreach ($this->jsPositions as $position) { |
| 400 | + foreach (ArrayHelper::getValue($view->js, $position, []) as $key => $js) { |
| 401 | + if (isset($jsBefore[$position][$key])) { |
| 402 | + continue; |
| 403 | + } |
| 404 | + $jsTemplates[$key] = $js; |
| 405 | + unset($view->js[$position][$key]); |
| 406 | + } |
| 407 | + } |
| 408 | + } |
381 | 409 |
|
382 | 410 | $options = Json::encode(array_merge([ |
383 | 411 | 'id' => $this->id, |
384 | 412 | 'inputId' => $this->context->options['id'], |
385 | 413 | 'template' => $template, |
386 | | - 'jsInit' => $jsCollector->getJsInit(), |
387 | | - 'jsTemplates' => $jsCollector->getJsTemplates(), |
| 414 | + 'jsInit' => $jsInit, |
| 415 | + 'jsTemplates' => $jsTemplates, |
388 | 416 | 'max' => $this->max, |
389 | 417 | 'min' => $this->min, |
390 | 418 | 'attributes' => $this->prepareJsAttributes(), |
@@ -416,7 +444,7 @@ private function registerJsSortable() |
416 | 444 | /** |
417 | 445 | * Returns an array of JQuery sortable plugin options. |
418 | 446 | * You can override this method extend plugin behaviour. |
419 | | - * |
| 447 | + * |
420 | 448 | * @return array |
421 | 449 | */ |
422 | 450 | protected function getJsSortableOptions() |
|
0 commit comments