/** * Runs the widget. */ public function run() { // Print elfinder widget in modal Modal::begin(['toggleButton' => false, 'id' => $this->options['id'] . '-dialog', 'size' => Modal::SIZE_LARGE]); echo ElFinder::widget(['language' => $this->language, 'controller' => $this->controller, 'path' => $this->path, 'filter' => 'image', 'callbackFunction' => new JsExpression('function(file, id){ console.log( file.url, "' . $this->buttonOptions['id'] . '" ); $("#' . $this->options['id'] . '").val( file.url ); $("#' . $this->options['id'] . '-thumb").attr("src", file.url ).show(); $("#' . $this->options['id'] . '-dialog").modal("hide"); }'), 'path' => $this->path, 'frameOptions' => ['style' => 'width: 100%; height: 500px; border: 0px;']]); Modal::end(); // Render input and upload button if ($this->hasModel()) { $attr = $this->attribute; $hidden = $this->model->{$attr} ? '' : 'display:none;'; $replace['{image}'] = '<img id="' . $this->options['id'] . '-thumb" class="thumbnail" src="' . $this->model->{$attr} . '" style="max-width: 150px; max-height: 150px; ' . $hidden . '" />'; $replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $hidden = $this->value ? '' : 'display:none;'; $replace['{image}'] = '<img id="' . $this->options['id'] . '-thumb" src="' . $this->value . '" style="max-width: 150px; max-height: 150px; ' . $hidden . '" />'; $replace['{input}'] = Html::textInput($this->name, $this->value, $this->options); } $replace['{button}'] = Html::tag($this->buttonTag, $this->buttonName, $this->buttonOptions); echo strtr($this->template, $replace); // Publish assets AssetsCallBack::register($this->getView()); if (!empty($this->multiple)) { $this->getView()->registerJs("\n\n mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ",\n function(files, id){\n var _f = [];\n for (var i in files) { _f.push(files[i].url); }\n \$('#' + id).val(_f.join(', ')).trigger('change');\n return true;\n });\n\n \$(document).on('click','#" . $this->buttonOptions['id'] . "',\n function(){\n mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");\n }\n );"); } else { $this->getView()->registerJs("\n\n mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){\n \$('#' + id).val(file.url).trigger('change');\n return true;\n });\n\n \$(document).on('click',\n '#" . $this->buttonOptions['id'] . "',\n function(){\n //mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");\n \$('#" . $this->options['id'] . "-dialog').modal('show');\n }\n );"); } }
public function run() { // Добавляем callback метод elfinder AssetsCallBack::register($this->getView()); $this->getView()->registerJs("mihaildev.elFinder.register('elFinderInsertImage', function(file, id) {\n tinymce.activeEditor.windowManager.getParams().setUrl(file.url);\n tinymce.activeEditor.windowManager.close();\n });\n\n function elFinderBrowser (field_name, url, type, win) {\n tinymce.activeEditor.windowManager.open({\n file: '/admin/elfinder/manager?callback=elFinderInsertImage&lang=ru&path={$this->filemanager['webpath']}',\n title: 'Менеджер файлов',\n width: 900,\n height: 450,\n resizable: 'yes'\n }, {\n setUrl: function (url) {\n\n var reg = /\\/[^/]+?\\/\\.\\.\\//;\n //var info = file.name;\n\n while(url.match(reg)) {\n url = url.replace(reg, '/');\n }\n\n win.document.getElementById(field_name).value = url;\n }\n });\n return false;\n }"); echo TinyMce::widget(['attribute' => $this->attribute, 'model' => $this->model, 'options' => $this->options, 'language' => $this->language, 'clientOptions' => $this->clientOptions]); }
public function run() { if ($this->hasModel()) { $replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $replace['{input}'] = Html::textInput($this->name, $this->value, $this->options); } $replace['{button}'] = Html::button($this->buttonName, $this->buttonOptions); $replace['{preview}'] = Html::a($this->previewButtonName, "#" . $this->previewButtonOptions['id'] . '_popup', $this->previewButtonOptions) . ' <div id="' . $this->previewButtonOptions['id'] . '_popup" class="modal fade" tabindex="-1" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h5 class="modal-title"><i class="fa fa-picture-o"></i> Preview</h5> </div> <div class="modal-body has-padding"> <img width="100%" src="' . $this->suffix . $this->model->{$this->attribute} . '"> </div> <div class="modal-footer"> <button class="btn btn-warning" data-dismiss="modal"><i class="fa fa-times"></i> Close</button> </div> </div> </div> </div>'; echo strtr($this->template, $replace); AssetsCallBack::register($this->getView()); if (!empty($this->multiple)) { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(files, id){ var _f = []; for (var i in files) { _f.push(files[i].url); } \$('#' + id).val(_f.join(', ')); return true;}); \$('#" . $this->buttonOptions['id'] . "').click(function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } else { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){\r\n\t \$('#' + id).val(file.url.replace('" . $this->suffix . "', ''));\r\n\t \$('#' + id + '_preview_popup .modal-body').html('<img width=\"100%\" src=\"' + file.url + '\">'); return true;}); \$('#" . $this->buttonOptions['id'] . "').click(function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } }
public function run() { AssetsCallBack::register($this->getView()); echo Html::tag($this->tag, $this->name, $this->options); $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->_managerOptions['id']) . ", " . Json::encode($this->callback) . ");"); // register callback Function $this->getView()->registerJs("\$(document).on('click', '#" . $this->options['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); //on click button open manager }
/** * Runs the widget. */ public function run() { if ($this->hasModel()) { $replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $replace['{input}'] = Html::textInput($this->name, $this->value, $this->options); } $replace['{button}'] = Html::tag($this->buttonTag, $this->buttonName, $this->buttonOptions); echo strtr($this->template, $replace); AssetsCallBack::register($this->getView()); if (!empty($this->multiple)) { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(files, id){ var _f = []; for (var i in files) { _f.push(files[i].url); } \$('#' + id).val(_f.join(', ')).trigger('change', [files, id]); return true;}); \$(document).on('click','#" . $this->buttonOptions['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } else { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){ \$('#' + id).val(file.url).trigger('change', [file, id]);; return true;}); \$(document).on('click', '#" . $this->buttonOptions['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } }
/** * Runs the widget. */ public function run() { if ($this->hasModel()) { $replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $replace['{input}'] = Html::textInput($this->name, $this->value, $this->options); } $replace['{button}'] = Html::button($this->buttonName, $this->buttonOptions); echo strtr($this->template, $replace); AssetsCallBack::register($this->getView()); if (!empty($this->callbackFunction)) { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . "," . Json::encode($this->callbackFunction) . ");\$('#" . $this->buttonOptions['id'] . "').click(function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } else { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){ \$('#' + id).val(file.url); return true;});\$('#" . $this->buttonOptions['id'] . "').click(function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } }
/** * Runs the widget. */ public function run() { $images = $this->model->{$this->attribute}; $galleryItems = array_map(function ($value) { return ['url' => isset($value['url']) ? $value['url'] : '', 'src' => isset($value['url']) ? $value['url'] : '', 'options' => $value]; }, $images); Gallery::widget(); if ($this->hasModel()) { $replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $replace['{input}'] = Html::textInput($this->name, $this->value, $this->options); } $replace['{button}'] = Html::tag($this->buttonTag, $this->buttonName, $this->buttonOptions); echo strtr($this->template, $replace); AssetsCallBack::register($this->getView()); if (!empty($this->multiple)) { $this->getView()->registerJs("ElFinderFileCallback.register(" . Json::encode($this->options['id']) . ", function(files, id){ var _f = []; for (var i in files) { _f.push(files[i].url); } \$('#' + id).val(_f.join(', ')); return true;}); \$(document).on('click','#" . $this->buttonOptions['id'] . "', function(){ElFinderFileCallback.openManager(" . Json::encode($this->_managerOptions) . ");});"); } else { $this->getView()->registerJs("ElFinderFileCallback.register(" . Json::encode($this->options['id']) . ", function(file, id){ \$('#' + id).val(file.url); return true;}); \$(document).on('click', '#" . $this->buttonOptions['id'] . "', function(){ElFinderFileCallback.openManager(" . Json::encode($this->_managerOptions) . ");});"); } }
public function run() { $container = 'div'; if (isset($this->containerOptions['tag'])) { $container = $this->containerOptions['tag']; unset($this->containerOptions['tag']); } echo Html::tag($container, Html::tag('iframe', '', $this->frameOptions), $this->containerOptions); if (!empty($this->callbackFunction)) { AssetsCallBack::register($this->getView()); $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->id) . "," . Json::encode($this->callbackFunction) . ");"); } }
<?php $this->bodyClass = 'com_widgetkit'; $this->params['actions_buttons'] = [['label' => Yii::t('admin', 'Create'), 'options' => ['form' => 'content-articles-id', 'type' => 'submit'], 'icon' => 'fa fa-save', 'color' => 'btn-success']]; \mihaildev\elfinder\AssetsCallBack::register($this); $app->handle();
public function registerJs() { AssetsCallBack::register($this->getView()); $js = "mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){\n \$('#' + id).val(file.url); return true;\n });\n \$('#" . $this->buttonOptions['id'] . "').click(function(){\n mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"; $this->getView()->registerJs($js); $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){\n var img;\n if((\"url\" in file )){\n img = templateItem.replace('{src}', file.url).replace('{src}', file.url);\n \$('#{$this->previewId}').append(img);\n } else {\n file.forEach(function(item){\n img = templateItem.replace('{src}', item.url).replace('{src}', item.url);\n \$('#{$this->previewId}').append(img);\n });\n }\n return true;}); "); $hiddenInput = Html::activeHiddenInput($this->model, $this->attribute . '[]', ['value' => '{src}']); $templateJS = 'var templateItem = \'<div class="image-preview-wrap"> <div class="image-preview"> <img src="{src}" alt=""> </div> <div class="delete-button"> <a class="delete-image"> <span class="glyphicon glyphicon-remove"></span> </a> </div> ' . $hiddenInput . ' </div>\';'; $this->getView()->registerJs(str_replace(["\r", "\n"], '', $templateJS), \yii\web\View::POS_END); $deleteJs = '$(document).on("click", ".delete-button", function(){$(this).parent().remove()});'; $this->getView()->registerJs($deleteJs); $this->view->registerCss('.form-img-preview {max-width:100px;}'); $this->view->registerCss('.image-preview img {max-width:200px;}'); $this->view->registerCss('.image-preview-wrap {position: relative;display: inline-block;max-width: 200px;margin: 10px;}'); $this->view->registerCss('.delete-button {top: 0;position: absolute;right: 0;}'); }