Skip to content

Commit

Permalink
Merge pull request #47 from helios-ag/cmf
Browse files Browse the repository at this point in the history
Uglify support, optional compession
  • Loading branch information
helios-ag committed Oct 3, 2013
2 parents 9e91d5d + 1cc59b5 commit 96a8b42
Show file tree
Hide file tree
Showing 18 changed files with 371 additions and 67 deletions.
24 changes: 19 additions & 5 deletions Controller/ElfinderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

/**
* Loader service for Elfinder backend
* displays Elfinder
Expand All @@ -22,23 +23,36 @@ public function showAction()
$editor = $parameters['editor'];
$locale = $parameters['locale'];
$fullscreen = $parameters['fullscreen'];
$includeAssets = $parameters['include_assets'];
$compression = $parameters['compression'];
$prefix = ($compression ? '/compressed' : '');
switch ($editor){
case 'ckeditor':
return $this->render('FMElfinderBundle:Elfinder:ckeditor.html.twig', array('locale' => $locale, 'fullscreen' => $fullscreen));
return $this->render('FMElfinderBundle:Elfinder'.$prefix.':ckeditor.html.twig', array(
'locale' => $locale,
'fullscreen' => $fullscreen,
'includeAssets' => $includeAssets
));
break;
case 'tinymce':
return $this->render('FMElfinderBundle:Elfinder:tinymce.html.twig', array(
return $this->render('FMElfinderBundle:Elfinder'.$prefix.':tinymce.html.twig', array(
'locale' => $locale,
'tinymce_popup_path' => $this->getAssetsUrl($parameters['tinymce_popup_path'])
'tinymce_popup_path' => $this->getAssetsUrl($parameters['tinymce_popup_path']),
'includeAssets' => $includeAssets,
));
break;
case 'tinymce4':
return $this->render('FMElfinderBundle:Elfinder:tinymce4.html.twig', array(
return $this->render('FMElfinderBundle:Elfinder'.$prefix.':tinymce4.html.twig', array(
'locale' => $locale,
'includeAssets'=>$includeAssets
));
break;
default:
return $this->render('FMElfinderBundle:Elfinder:simple.html.twig', array('locale' => $locale, 'fullscreen' => $fullscreen));
return $this->render('FMElfinderBundle:Elfinder'.$prefix.':simple.html.twig', array(
'locale' => $locale,
'fullscreen' => $fullscreen,
'includeAssets' => $includeAssets,
));
}
}

Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ public function getConfigTreeBuilder()
->scalarNode('locale')->defaultValue('en_US.UTF8')->end()
->booleanNode('showhidden')->defaultValue(false)->end()
->scalarNode('editor')->defaultValue('simple')->end()
->booleanNode('compression')->defaultValue(false)->end()
->booleanNode('fullscreen')->defaultValue(true)->end()
->booleanNode('include_assets')->defaultValue(true)->end()
->scalarNode('tinymce_popup_path')->defaultValue('')->end()
->end()
;
$this->addConnectorSection($rootNode);
return $treeBuilder;
}

/**
* @param ArrayNodeDefinition $rootNode
*/
private function addConnectorSection(ArrayNodeDefinition $rootNode)
{
$rootNode
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Creation is inspired by simplicity and convenience of Finder program used in Mac
- [Step 1: Installation:](#step-1-installation-1)
- [Step 2: Configure CKEditor setting via settings.yml or through form builder:](#step-2-configure-ckeditor-setting-via-settingsyml-or-through-form-builder)
- [Using ElFinder with TinyMCE](#using-elfinder-with-tinymce)
- [Using ElfinderBundle with TinyMCEBundle](#using-elfinderbundle-with-tinymcebundle)
- [Using ElfinderBundle with TinyMCEBundle](#using-elfinderbundle-with-tinymcebundle)
- [Integrating with TinyMCE 4.x](#integrating-with-tinymce-4x)

## Installation
Expand Down Expand Up @@ -97,8 +97,11 @@ ROLE_USER is provided as example.

### Step 5: Configure assetic

Under assetic section of your config.yml, add FMElfinderBundle to bundles section, also enable yui compressor.
Under assetic section of your config.yml, add FMElfinderBundle to bundles section, also you can enable uglify js/css
compressor (also you need to enable option "compression: true" under bundle configuration).

Also set "use_controller: false".

``` yaml
assetic:
debug: %kernel.debug%
Expand All @@ -107,10 +110,11 @@ assetic:
java: /usr/bin/java
filters:
cssrewrite: ~
yui_css:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
yui_js:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
uglifyjs2:
# the path to the uglifyjs executable
bin: /usr/bin/uglifyjs
uglifycss:
bin: /usr/bin/uglifycss
```
### Step 6: Install and dump assets
Expand Down Expand Up @@ -216,7 +220,8 @@ ElFinder will be available under Insert Image dialog

You can integrate TinyMCE byself or use Bundles that already add TinyMCE functionality to your Symfony project.
Below instruction how to integrate [FMElfinderBundle](https://github.com/helios-ag/FMElfinderBundle) with [TinyMCEBundle](https://github.com/stfalcon/TinymceBundle)
## Using ElfinderBundle with [TinyMCEBundle](https://github.com/stfalcon/TinymceBundle)

### Using ElfinderBundle with [TinyMCEBundle](https://github.com/stfalcon/TinymceBundle)
Instruction for bundle version 0.2.1 (TinyMCE 3.x), instruction for TinyMCE 4.x, you can find at the end of this
document.
Download both bundles, configure, dump and install assets as written in installation steps
Expand Down Expand Up @@ -277,3 +282,8 @@ Thats all, Elfinder is integrated into TinyMCE.

Manual integration guide can be found [here](/INTEGRATION_GUIDE.md)


##Changelog

1.x
Switched from YUI compressor to Uglify
19 changes: 6 additions & 13 deletions Resources/views/Elfinder/ckeditor.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
<html>
<head>
<meta charset="utf-8">
{% stylesheets output='assetic/css/compiled/fmelfinder/main.css'
'bundles/fmelfinder/css/*' filter='cssrewrite,?yui_css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% if includeAssets %}
{% include "FMElfinderBundle:Elfinder:helper/assets_css.html.twig" %}
{% endif %}
</head>
<body>
{% javascripts output='assetic/js/compiled/fmelfinder/main.js' filter='?yui_js'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-1.8.0.min.js'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-ui-1.8.23.custom.min.js'
'@FMElfinderBundle/Resources/public/js/elfinder.min.js'
'@FMElfinderBundle/Resources/public/js/i18n/*'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

{% if includeAssets %}
{% include "FMElfinderBundle:Elfinder:helper/assets_js.html.twig" %}
{% endif %}
<script type="text/javascript" charset="utf-8">
function getUrlParam(paramName) {
var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
Expand Down
20 changes: 20 additions & 0 deletions Resources/views/Elfinder/compressed/_tinymce.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script type="text/javascript">
//<![CDATA[
function elFinderBrowser (field_name, url, type, win) {
tinyMCE.activeEditor.windowManager.open({
file: "{{ url('elfinder') }}",
title: 'elFinder 2.0',
width: 900,
height: 450,
resizable: 'yes',
inline: 'yes',
popup_css: false,
close_previous: 'no'
}, {
window: win,
input: field_name
});
return false;
}
//]]>
</script>
16 changes: 16 additions & 0 deletions Resources/views/Elfinder/compressed/_tinymce4.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script type="text/javascript">
function elFinderBrowser (field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
file:"{{ url('elfinder') }}",
title: 'elFinder 2.0',
width: 900,
height: 450,
resizable: 'yes'
}, {
setUrl: function (url) {
win.document.getElementById(field_name).value = url;
}
});
return false;
}
</script>
58 changes: 58 additions & 0 deletions Resources/views/Elfinder/compressed/ckeditor.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
{% stylesheets output='assetic/css/compiled/fmelfinder/main.css'
'bundles/fmelfinder/css/*' filter='cssrewrite,?yui_css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
</head>
<body>
{% javascripts output='assetic/js/compiled/fmelfinder/main.js' filter='?yui_js'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-1.8.0.min.js'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-ui-1.8.23.custom.min.js'
'@FMElfinderBundle/Resources/public/js/elfinder.min.js'
'@FMElfinderBundle/Resources/public/js/i18n/*'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

<script type="text/javascript" charset="utf-8">
function getUrlParam(paramName) {
var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
var match = window.location.search.match(reParam) ;
return (match && match.length > 1) ? match[1] : '' ;
}
$().ready(function() {
var funcNum = getUrlParam('CKEditorFuncNum');
var mode = getUrlParam('mode');
var f = $('#elfinder').elfinder({
url : '{{path('ef_connect')}}'+'?mode='+mode,
lang : '{{locale}}',
getFileCallback : function(file) {
if (funcNum) {
window.opener.CKEDITOR.tools.callFunction(funcNum, file.url);
window.close();
}
}
});
{% if fullscreen %}
$(window).resize(function(){
var h = $(window).height();
if($('#elfinder').height() != h - 20){
$('#elfinder').height(h -20).resize();
}
});
{% endif %}
});
</script>
<div id="elfinder"></div>
</body>
</html>



38 changes: 38 additions & 0 deletions Resources/views/Elfinder/compressed/simple.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
{% stylesheets output='assetic/css/compiled/fmelfinder/main.css'
'bundles/fmelfinder/css/*' filter='cssrewrite,?uglifycss' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
</head>
<body>
{% javascripts output='bundles/fmelfinder/js/main.js' filter='?uglifyjs2'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-1.8.0.min.js'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-ui-1.8.23.custom.min.js'
'@FMElfinderBundle/Resources/public/js/elfinder.min.js'
'@FMElfinderBundle/Resources/public/js/i18n/*'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
<script type="text/javascript" charset="utf-8">
$().ready(function() {
var $f = $('#elfinder').elfinder({
url : '{{path('ef_connect')}}',
lang : '{{locale}}'
});
{% if fullscreen %}
var $window = $(window);
$window.resize(function(){
var $win_height = $window.height();
if( $f.height() != $win_height ){
$f.height($win_height).resize();
}
});
{% endif %}
});
</script>
<div id="elfinder"></div>
</body>
</html>
70 changes: 70 additions & 0 deletions Resources/views/Elfinder/compressed/tinymce.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
{% stylesheets output='assetic/css/compiled/fmelfinder/main.css'
'bundles/fmelfinder/css/*' filter='cssrewrite,?uglifycss' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
</head>
<body>
{% javascripts output='bundles/fmelfinder/js/main.js' filter='?uglifyjs2'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-1.8.0.min.js'
'@FMElfinderBundle/Resources/public/js/jquery/jquery-ui-1.8.23.custom.min.js'
'@FMElfinderBundle/Resources/public/js/elfinder.min.js'
'@FMElfinderBundle/Resources/public/js/i18n/*'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
<script type="text/javascript" src="{{ tinymce_popup_path }}"></script>
<script type="text/javascript" charset="utf-8">
var FileBrowserDialogue = {
init: function() {
// Here goes your code for setting your custom things onLoad.
},
mySubmit: function (URL) {
var win = tinyMCEPopup.getWindowArg('window');
// pass selected file path to TinyMCE
win.document.getElementById(tinyMCEPopup.getWindowArg('input')).value = URL;
// are we an image browser?
if (typeof(win.ImageDialog) != 'undefined') {
// update image dimensions
if (win.ImageDialog.getImageData) {
win.ImageDialog.getImageData();
}
// update preview if necessary
if (win.ImageDialog.showPreviewImage) {
win.ImageDialog.showPreviewImage(URL);
}
}
// close popup window
tinyMCEPopup.close();
}
}
tinyMCEPopup.onInit.add(FileBrowserDialogue.init, FileBrowserDialogue);
$().ready(function() {
var f = $('#elfinder').elfinder({
url : '{{ path('ef_connect') }}',
lang : '{{ locale }}',
getfile : {
onlyURL : true,
multiple : false,
folders : false
},
getFileCallback : function(url) {
path = '/' + url.path;
FileBrowserDialogue.mySubmit(path);
}
}).elfinder('instance');
});
</script>
<div id="elfinder"></div>
</body>
</html>
Loading

0 comments on commit 96a8b42

Please sign in to comment.