Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Oost committed Jul 11, 2018
2 parents efcf191 + 75df70b commit 768b07a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 90 deletions.
10 changes: 10 additions & 0 deletions FroalaEditorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ public function getCustomConfigOptions($dir)
return $options;
}

/**
* {@inheritdoc}
*/
public function registerUserPermissions()
{
return array(
'froala-allowCodeView' => array('label' => Craft::t('Enable HTML Code view button')),
);
}

/**
* @param string $msg
* @param string $logLevel
Expand Down
19 changes: 5 additions & 14 deletions fieldtypes/FroalaEditorFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ protected function defineSettings()
'assetsImagesSubPath' => [AttributeType::String],
'assetsFilesSource' => [AttributeType::Number, 'min' => 0],
'assetsFilesSubPath' => [AttributeType::String],
'customCssType' => [AttributeType::String],
'customCssFile' => [AttributeType::String],
'customCssClasses' => [AttributeType::String],
'customCssClassesOverride' => [AttributeType::Bool],
'enabledPlugins' => [AttributeType::Mixed],
'editorConfig' => [AttributeType::String],
];
}
Expand Down Expand Up @@ -213,7 +208,7 @@ private function getInputHtmlJavascript($id, BaseModel $pluginSettings, BaseMode
craft()->templates->includeJsResource('froalaeditor/js/FroalaEditorInput.js');

// Include a custom css files (per field or plugin-wide)
$this->includeCustomCSSFile($pluginSettings, $fieldSettings);
$this->includeCustomCSSFile($pluginSettings);

// get custom config (field OR plugin)
$customEditorConfig = craft()->froalaEditor_field
Expand All @@ -227,7 +222,7 @@ private function getInputHtmlJavascript($id, BaseModel $pluginSettings, BaseMode

$settings = [
'id' => $namespacedId,
'isAdmin' => craft()->userSession->isAdmin(),
'allowCodeView' => craft()->userSession->checkPermission('froala-allowCodeView'),
'editorConfig' => array_merge([
'craftLinkElementType' => 'Entry',
'craftLinkElementRefHandle' => 'entry',
Expand Down Expand Up @@ -261,14 +256,10 @@ private function getInputHtmlJavascript($id, BaseModel $pluginSettings, BaseMode
* @param BaseModel $pluginSettings
* @param BaseModel $fieldSettings
*/
private function includeCustomCSSFile(BaseModel $pluginSettings, BaseModel $fieldSettings)
private function includeCustomCSSFile(BaseModel $pluginSettings)
{
$customCssType = $fieldSettings->getAttribute('customCssType');
$customCssFile = $fieldSettings->getAttribute('customCssFile');
if (empty($customCssFile)) {
$customCssType = $pluginSettings->getAttribute('customCssType');
$customCssFile = $pluginSettings->getAttribute('customCssFile');
}
$customCssType = $pluginSettings->getAttribute('customCssType');
$customCssFile = $pluginSettings->getAttribute('customCssFile');

if (!empty($customCssFile)) {

Expand Down
11 changes: 11 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[
{
"version": "2.8.1",
"downloadUrl": "https://github.com/froala/Craft-Froala-WYSIWYG/archive/v2.8.1.zip",
"date": "2018-07-11T23:25:00+02:00",
"notes": [
"[Added] Permission to grant users or groups to toggle HTML code view (not admins only).",
"[Fixed] Issue regarding loading enabled-plugin values based on the library & core plugins.",
"[Improved] Removed code view option via plugin settings (since it's a permission now).",
"[Improved] Removed custom css settings from field. Use globally plugin setting instead (compatible with Craft 3 version)."
]
},
{
"version": "2.8.1-RC4",
"downloadUrl": "https://github.com/froala/Craft-Froala-WYSIWYG/archive/v2.8.1-rc.4.zip",
Expand Down
20 changes: 4 additions & 16 deletions resources/js/FroalaEditorConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,8 @@

var list = {};

if (this.fieldSettings.customCssClassesOverride !== '1') {
var pluginRows = this.pluginSettings.customCssClasses;
$.each(pluginRows, function (index, value) {
list[value.className] = value.displayName;
});
}

var fieldRows = this.fieldSettings.customCssClasses;
$.each(fieldRows, function (index, value) {
var pluginRows = this.pluginSettings.customCssClasses;
$.each(pluginRows, function (index, value) {
list[value.className] = value.displayName;
});

Expand All @@ -54,12 +47,7 @@
}

var list = [],
enabledPlugins = this.pluginSettings.enabledPlugins,
fieldPlugins = this.fieldSettings.enabledPlugins;

if (fieldPlugins !== '*' && $.isArray(fieldPlugins)) {
enabledPlugins = fieldPlugins;
}
enabledPlugins = this.pluginSettings.enabledPlugins;

if (enabledPlugins !== '*' && $.isArray(enabledPlugins)) {
for (var i = 0; i < enabledPlugins.length; i++) {
Expand Down Expand Up @@ -212,7 +200,7 @@
break;
}

if (this.settings.isAdmin) {
if (this.settings.allowCodeView) {
buttons.push('html');
}

Expand Down
46 changes: 35 additions & 11 deletions services/FroalaEditor_FieldService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class FroalaEditor_FieldService extends BaseApplicationComponent
*/
protected $plugin;

/**
* @var array
*/
private $loadedPlugins = [];

/**
* Return the plugin instance
*
Expand Down Expand Up @@ -118,27 +123,46 @@ public function getCustomConfig(BaseModel $settings, $settingsKey, $subDir)
*/
public function getAllEditorPlugins()
{
$pluginDir = dirname(__DIR__) . DIRECTORY_SEPARATOR;
$pluginDir .= implode(DIRECTORY_SEPARATOR, [
if (empty($this->loadedPlugins)) {

$ds = DIRECTORY_SEPARATOR;
$path = dirname(__DIR__) . $ds;
$path .= implode($ds, [
'resources',
'lib',
'v' . $this->getPlugin()->getEditorVersion(),
'js',
'plugins',
]) . DIRECTORY_SEPARATOR;
]) . $ds;
$plugins = [];

$files = FileHelper::findFiles($path, [
'level' => -1,
'exclude' => ['quick_insert.min.js', 'code_view.min.js'],
]);

foreach ($files as $pluginFile) {
if (substr($pluginFile, -6) !== 'min.js') {
continue;
}

$fileName = basename($pluginFile);
$pluginName = str_replace('.min.js', '', $fileName);
$pluginLabel = str_replace('_', ' ', $pluginName);
$pluginLabel = ucwords($pluginLabel);

$plugins[$pluginName] = $pluginLabel;
}

$plugins = [];
foreach (glob($pluginDir . '*.min.js') as $pluginFile) {
$fileName = basename($pluginFile);
$pluginName = str_replace('.min.js', '', $fileName);
// add-in core plugins
$plugins = array_merge($plugins, self::CORE_PLUGINS);

$pluginLabel = str_replace('_', ' ', $pluginName);
$pluginLabel = ucwords($pluginLabel);
ksort($plugins);

$plugins[$pluginName] = $pluginLabel;
$this->loadedPlugins = $plugins;
}

return $plugins;
return $this->loadedPlugins;
}

/**
Expand Down
49 changes: 0 additions & 49 deletions templates/fieldtype/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,6 @@

<hr>

{{ forms.field({
label: 'Custom CSS File'|t,
instructions: 'Include a custom style file for the editor to display content in your style. This file path could be a plugin resource or should be a relative to your site\'s document root path.'|t,
errors: settings.getErrors('customCssFile')
}, macros.customCssInput('customCss', settings)) }}

{{ forms.hidden({
name: 'customCssClasses',
value: ''
}) }}

{{ forms.editableTableField({
id: 'customCssClasses',
name: 'customCssClasses',
label: 'Paragraph CSS Classes'|t,
instructions: 'Add extra Paragraph Style classes.'|t,
rows: settings.customCssClasses,
cols: {
className: {
heading: 'CSS Class Name(s))'|t,
type: 'text'
},
displayName: {
heading: 'Display Name'|t,
type: 'text'
}
}
}) }}

{{ forms.lightswitchField({
id: 'froala-custom-css-classes-override',
name: 'customCssClassesOverride',
label: 'Override CSS settings' | t('froala-editor'),
instructions: 'Override the plugin CSS settings instead of concatenate them together.' | t('froala-editor')
}) }}

<hr>

{{ forms.checkboxSelectField({
label: 'Enabled Plugins'|t,
instructions: 'Enable or disable plugins to use for the editor.'|t,
id: 'enabledPlugins',
name: 'enabledPlugins',
options: editorPlugins,
values: settings.enabledPlugins
}) }}

<hr>

{{ forms.selectField({
id: 'froala-editor-config',
label: "Custom Editor Config"|t(),
Expand Down

0 comments on commit 768b07a

Please sign in to comment.