Skip to content

Commit

Permalink
Handle rob006/yii-tinymce v2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 committed Jan 9, 2024
1 parent ce44c95 commit dfe4a8e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
27 changes: 24 additions & 3 deletions TinyMceElFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,28 @@ public function getFileBrowserCallback() {
$connectorUrl = CJSON::encode(Yii::app()->controller->createUrl($this->popupConnectorRoute, $this->popupConnectorParams));
$title = CJSON::encode($this->popupTitle);

/* @noinspection ALL */
$script = <<<JS
$tinymceVersion = 4;
if (method_exists($this, 'getTinymceVersion')) {
$tinymceVersion = $this->getTinymceVersion();
}
if ($tinymceVersion === 6) {
/* @noinspection ALL */
$script = <<<JS
function (callback, value, meta) {
window.tinymceImageUploadCallback = callback;
tinymce.activeEditor.windowManager.openUrl({
url: $connectorUrl,
title: $title,
width: 900,
height: 450,
resizable: "yes"
});
return false;
}
JS;
} else {
/* @noinspection ALL */
$script = <<<JS
function (field_name, url, type, win) {
tinymce.activeEditor.windowManager.open(
{
Expand All @@ -44,9 +64,10 @@ function (field_name, url, type, win) {
}
}
);
return false;
window.tinymceImageUploadCallback = tinymce.activeEditor.windowManager.getParams().setUrl;
}
JS;
}
return 'js:' . $script;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"yiisoft/yii": "~1.1.18"
},
"require-dev": {
"rob006/yii-tinymce": "^1.0"
"rob006/yii-tinymce": "^1.0 | ^2.0"
},
"replace": {
"studio-42/elfinder": "2.1.64"
Expand Down
7 changes: 7 additions & 0 deletions views/ServerFileInputElFinderPopupAction.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?php

/* @var $settings array */
/* @var $title string */
/* @var $fieldId string */

?>
<!DOCTYPE html>
<html>
<head>
Expand Down
8 changes: 7 additions & 1 deletion views/TinyMceElFinderPopupAction.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<?php

/* @var $settings array */
/* @var $title string */

?>
<!DOCTYPE html>
<html>
<head>
Expand All @@ -11,7 +17,7 @@
},
mySubmit: function(URL) {
// pass selected file path to TinyMCE
parent.tinymce.activeEditor.windowManager.getParams().setUrl(URL);
parent.tinymceImageUploadCallback(URL);

// close popup window
parent.tinymce.activeEditor.windowManager.close();
Expand Down

0 comments on commit dfe4a8e

Please sign in to comment.