Example #1
0
 /**
  * Registers tinyMCE js plugin
  */
 protected function registerClientScript()
 {
     $js = [];
     $view = $this->getView();
     TinyMceAsset::register($view);
     $id = $this->options['id'];
     $this->clientOptions = ['menubar' => !Yii::$app->user->isGuest, 'statusbar' => !Yii::$app->user->isGuest, 'plugins' => ["advlist autolink link image lists charmap print preview hr anchor pagebreak", "searchreplace wordcount visualblocks visualchars insertdatetime media nonbreaking", "table contextmenu directionality emoticons paste textcolor code"], 'toolbar1' => "undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | styleselect", 'toolbar2' => "| link unlink anchor | image media | forecolor backcolor ", 'height' => '500px', 'relative_urls' => false];
     $this->clientOptions['selector'] = "#{$id}";
     // @codeCoverageIgnoreStart
     /*if ($this->language !== null) {
           $langFile = "langs/{$this->language}.js";
           $langAssetBundle = TinyMceLangAsset::register($view);
           $langAssetBundle->js[] = $langFile;
           $this->clientOptions['language_url'] = $langAssetBundle->baseUrl . "/{$langFile}";
       }*/
     // @codeCoverageIgnoreEnd
     if ($this->enableFilemanager && !Yii::$app->user->isGuest) {
         $kcfinder = KCFinderAsset::register($view);
         $this->clientOptions['file_browser_callback'] = new \yii\web\JsExpression("\n            function(field, url, type, win) {\n                var fileType = " . Json::encode($this->folderName) . ";\n                tinyMCE.activeEditor.windowManager.open({\n                    file: '" . $kcfinder->baseUrl . "/browse.php?opener=tinymce4&field=' + field + '&type=' + fileType[type],\n                    title: 'File manager',\n                    width: 700,\n                    height: 500,\n                    inline: true,\n                    close_previous: false\n                }, {\n                    window: win,\n                    input: field\n                });\n                return false;\n            }");
         $kcfOptions = ['disabled' => false, 'uploadDir' => $this->uploadDir, 'uploadURL' => $this->uploadURL, 'types' => array('files' => "", 'flash' => "swf", 'images' => "*img", 'file' => "", 'media' => "swf flv avi mpg mpeg qt mov wmv asf rm", 'image' => "*img", 'File' => "", 'Media' => "swf flv avi mpg mpeg qt mov wmv asf rm", 'Image' => "*img")];
         Yii::$app->session->set('KCFINDER', $kcfOptions);
         $htSource = __DIR__ . '/upload.htaccess';
         $htDest = $kcfinder->basePath . '/conf/upload.htaccess';
         copy($htSource, $htDest);
     }
     $options = Json::encode($this->clientOptions);
     $js[] = "tinymce.init({$options});";
     if ($this->triggerSaveOnBeforeValidateForm) {
         $js[] = "\$('#{$id}').parents('form').on('beforeValidate', function() { tinymce.triggerSave(); });";
     }
     $view->registerJs(implode("\n", $js));
 }
    protected function registerJs()
    {
        $view = $this->getView();
        $kcfinder = KCFinderAsset::register($view);
        $widgetId = $this->widget['id'];
        $btnBrowse = $this->widget['id'] . '-btn-browse';
        $btnClear = $this->widget['id'] . '-btn-clear';
        $js = [];
        $js[] = <<<JS
function openKCFinder(field, img) {
    window.KCFinder = {
        callBack: function(url) {
            field.value = url;
            if (typeof img !== "undefined") {
                img.src = field.value;
            }
            window.KCFinder = null;
        }
    };
    window.open('{$kcfinder->baseUrl}/browse.php?type={$this->type}&dir={$this->dir}', 'kcfinder_textbox',
        'status=0, toolbar=0, location=0, menubar=0, directories=0, ' +
        'resizable=1, scrollbars=0, width=800, height=600'
    );
}
JS;
        $view->registerJs(implode("\n", $js), $view::POS_HEAD);
        $jsBtn = [];
        $jsBtn[] = <<<JSBTN

\$("#{$btnBrowse}").click(function(e){
    e.preventDefault()
    var textInput = document.getElementById("{$widgetId}");
    var img = document.getElementById("{$widgetId}-preview");
    openKCFinder(textInput, img);
});

\$('#{$widgetId}').on("propertychange change keyup paste input", function(){
    \$('#{$widgetId}-preview').addClass('img-responsive');
    if(\$(this).val() == ''){
        \$('#{$widgetId}-preview').attr('src', '{$this->src}');
    }else{
        \$('#{$widgetId}-preview').attr('src', \$(this).val());
    }
});

\$("#{$btnClear}").click(function(e){
    e.preventDefault()
    \$("#{$widgetId}").val('');
    \$('#{$widgetId}').change();
});
JSBTN;
        $view->registerJs(implode("\n", $jsBtn));
    }
Example #3
0
 /**
  * Registers CKEditor plugin
  * @codeCoverageIgnore
  */
 protected function registerPlugin()
 {
     $js = [];
     $view = $this->getView();
     CKEditorAsset::register($view);
     $id = $this->options['id'];
     if ($this->filemanager) {
         $kcfinder = KCFinderAsset::register($view);
         $browse = ['filebrowserBrowseUrl' => $kcfinder->baseUrl . '/browse.php?opener=ckeditor&type=files', 'filebrowserImageBrowseUrl' => $kcfinder->baseUrl . '/browse.php?opener=ckeditor&type=images', 'filebrowserFlashBrowseUrl' => $kcfinder->baseUrl . '/browse.php?opener=ckeditor&type=flash', 'filebrowserUploadUrl' => $kcfinder->baseUrl . '/upload.php?opener=ckeditor&type=files', 'filebrowserImageUploadUrl' => $kcfinder->baseUrl . '/upload.php?opener=ckeditor&type=images', 'filebrowserFlashUploadUrl' => $kcfinder->baseUrl . '/upload.php?opener=ckeditor&type=flash'];
         $this->clientOptions = ArrayHelper::merge($this->clientOptions, $browse);
         $kcfOptions = ['disabled' => false, 'uploadDir' => $this->uploadDir, 'uploadURL' => $this->uploadURL];
         Yii::$app->session->set('KCFINDER', $kcfOptions);
         $htSource = __DIR__ . '/upload.htaccess';
         $htDest = $kcfinder->basePath . '/conf/upload.htaccess';
         copy($htSource, $htDest);
     }
     $options = $this->clientOptions !== false && !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '{}';
     $js[] = "CKEDITOR.replace('{$id}', {$options});";
     $view->registerJs(implode("\n", $js));
 }