Skip to content

Commit

Permalink
bugfix: close button issue on integration with CKEditor #108
Browse files Browse the repository at this point in the history
  • Loading branch information
psolom committed Feb 16, 2017
1 parent af7cda0 commit 08f3b89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 55 deletions.
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
<span>&nbsp;</span>
</button>
</div>
<!-- ko if: headerModel.closeButton() -->
<div class="button-group">
<button class="fm-btn-close no-label" type="button" data-bind="click: headerModel.closeButtonOnClick, attr: {title: localizeGUI() ? lg().close : null}">
<span>&nbsp;</span>
</button>
</div>
<!-- /ko -->
</div>
</div>

Expand Down
86 changes: 33 additions & 53 deletions scripts/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@

(function($) {

// function to retrieve GET params
$.urlParam = function(name) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results) {
return results[1];
} else {
return 0;
}
};

$.richFilemanagerPlugin = function(element, pluginOptions)
{
/**
Expand Down Expand Up @@ -187,26 +177,11 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
// Forces columns to fill the layout vertically.
// Called on initial page load and on resize.
fm.setDimensions = function() {
var bheight = 0,
padding = $wrapper.outerHeight(true) - $wrapper.height();

if($.urlParam('CKEditorCleanUpFuncNum')) bheight +=60;
var padding = $wrapper.outerHeight(true) - $wrapper.height(),
newH = $(window).height() - $header.height() - $footer.height() - padding,
newW = $splitter.width() - $splitter.children(".splitter-bar-vertical").outerWidth() - $filetree.outerWidth();

var newH = $(window).height() - $header.height() - $footer.height() - padding - bheight;
$splitter.height(newH);

// // adjust height of filemanager if there are other DOM elemements on page
// var delta = $(document).height() - $(window).height();
// if(!$container.parent().is('body') && delta > 0) {
// var diff = newH - delta;
// newH = (diff > 0) ? diff : 1;
// $splitter.height(newH);
// }

// $splitter.children().outerHeight($splitter.height());

// adjustment for window horizontal resize
var newW = $splitter.width() - $splitter.children(".splitter-bar-vertical").outerWidth() - $filetree.outerWidth();
$fileinfo.width(newW);
};

Expand Down Expand Up @@ -304,7 +279,7 @@ $.richFilemanagerPlugin = function(element, pluginOptions)

// localize messages based on culture var or from URL
var localize = function() {
var langCode = $.urlParam('langCode');
var langCode = _url_.param('langCode');
var langPath = fm.settings.baseUrl + '/languages/';

function buildLangPath(code) {
Expand All @@ -313,7 +288,7 @@ $.richFilemanagerPlugin = function(element, pluginOptions)

return $.ajax()
.then(function() {
if(langCode != 0) {
if(langCode) {
// try to load lang file based on langCode in query params
return file_exists(buildLangPath(langCode))
.done(function() {
Expand Down Expand Up @@ -672,12 +647,11 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
}

// adding a close button triggering callback function if CKEditorCleanUpFuncNum passed
if($.urlParam('CKEditorCleanUpFuncNum')) {
$("body").append('<button id="fm-js-btn-close" type="button">' + lg.close + '</button>');

$('#fm-js-btn-close').click(function () {
parent.CKEDITOR.tools.callFunction($.urlParam('CKEditorCleanUpFuncNum'));
});
if(_url_.param('CKEditorCleanUpFuncNum')) {
fmModel.headerModel.closeButton(true);
fmModel.headerModel.closeButtonOnClick = function() {
parent.CKEDITOR.tools.callFunction(_url_.param('CKEditorCleanUpFuncNum'));
};
}

// input file replacement
Expand Down Expand Up @@ -1059,8 +1033,8 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
path: path
};

if($.urlParam('type')) {
queryParams.type = $.urlParam('type');
if(_url_.param('type')) {
queryParams.type = _url_.param('type');
}

$.ajax({
Expand Down Expand Up @@ -1377,8 +1351,8 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
mode: 'getfolder',
path: path
};
if($.urlParam('type')) {
queryParams.type = $.urlParam('type');
if(_url_.param('type')) {
queryParams.type = _url_.param('type');
}

$.ajax({
Expand Down Expand Up @@ -1663,6 +1637,12 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
};

var HeaderModel = function() {
this.closeButton = ko.observable(false);

this.closeButtonOnClick = function() {
console.log('clicked');
};

this.goHome = function() {
model.previewFile(false);
model.itemsModel.loadList(fileRoot);
Expand Down Expand Up @@ -2081,8 +2061,8 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
type = (typeof type === "undefined") ? "user" : type;

if(type === 'user') {
if($.urlParam('config') != 0) {
url = fm.settings.baseUrl + '/config/' + $.urlParam('config');
if(_url_.param('config')) {
url = fm.settings.baseUrl + '/config/' + _url_.param('config');
} else {
url = fm.settings.baseUrl + '/config/filemanager.config.json';
}
Expand Down Expand Up @@ -2482,9 +2462,9 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
return window.opener // window.open()
|| (window.parent && window.self !== window.parent) // <iframe>
|| window.tinyMCEPopup // tinyMCE >= 3.0
|| $.urlParam('field_name') // tinymce 4 or colorbox
|| $.urlParam('CKEditor') // CKEditor 3.0 + integration method
|| $.urlParam('ImperaviElementId'); // Imperavi Redactor I >= 10.x.x
|| _url_.param('field_name') // tinymce 4 or colorbox
|| _url_.param('CKEditor') // CKEditor 3.0 + integration method
|| _url_.param('ImperaviElementId'); // Imperavi Redactor I >= 10.x.x
}


Expand Down Expand Up @@ -2519,8 +2499,8 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
}

// tinymce 4 and colorbox
if($.urlParam('field_name')) {
parent.document.getElementById($.urlParam('field_name')).value = previewUrl;
if(_url_.param('field_name')) {
parent.document.getElementById(_url_.param('field_name')).value = previewUrl;

if(typeof parent.tinyMCE !== "undefined") {
parent.tinyMCE.activeEditor.windowManager.close();
Expand All @@ -2530,13 +2510,13 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
}
}

if($.urlParam('ImperaviElementId')) {
if(_url_.param('ImperaviElementId')) {
// use Imperavi Redactor I, tested on v.10.x.x
if (window.opener) {
// Popup
} else {
// Modal (in iframe)
var elementId = $.urlParam('ImperaviElementId'),
var elementId = _url_.param('ImperaviElementId'),
instance = parent.$('#'+elementId).redactor('core.getObject');

if(instance) {
Expand All @@ -2553,14 +2533,14 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
}

// CKEditor 3.0 + integration method
if($.urlParam('CKEditor')) {
if(_url_.param('CKEditor')) {
if (window.opener) {
// Popup
window.opener.CKEDITOR.tools.callFunction($.urlParam('CKEditorFuncNum'), previewUrl);
window.opener.CKEDITOR.tools.callFunction(_url_.param('CKEditorFuncNum'), previewUrl);
} else {
// Modal (in iframe)
parent.CKEDITOR.tools.callFunction($.urlParam('CKEditorFuncNum'), previewUrl);
parent.CKEDITOR.tools.callFunction($.urlParam('CKEditorCleanUpFuncNum'));
parent.CKEDITOR.tools.callFunction(_url_.param('CKEditorFuncNum'), previewUrl);
parent.CKEDITOR.tools.callFunction(_url_.param('CKEditorCleanUpFuncNum'));
}
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/filemanager.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions styles/filemanager.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ html[data-useragent*='MSIE 11.0'] .fm-container #newfile {
background-image: url(../images/folder_add.png);
}

.fm-container .fm-header .fm-btn-close span {
background-image: url(../images/reset.png);
}

.fm-container .fm-splitter {
height: 100%;
}
Expand Down

0 comments on commit 08f3b89

Please sign in to comment.