Skip to content

Commit

Permalink
fix filebrowserUploadUrl #4 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailDev committed Nov 19, 2014
1 parent b515a12 commit d20aa7f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ class Assets extends AssetBundle{

public $js = [
'ckeditor.js',
'js.js',
];

public $depends = [
'yii\web\YiiAsset',
];
}
9 changes: 8 additions & 1 deletion CKEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ public function run()
} else {
echo Html::textarea($this->name, $this->value, $this->options);
}

echo Html::endTag('div');
$js = [
'mihaildev.ckEditor.registerOnChange('.Json::encode($this->options['id']).');'
];

if(isset($this->editorOptions['filebrowserUploadUrl']))
$js[] = "mihaildev.ckEditor.registerCsrf();";

if(!isset($this->editorOptions['on']['instanceReady']))
$this->editorOptions['on']['instanceReady'] = new JsExpression("function( ev ){jQuery(CKEDITOR.instances[".Json::encode($this->options['id'])."].container.$).mouseleave(function() {CKEDITOR.instances[".Json::encode($this->options['id'])."].updateElement();});CKEDITOR.instances[".Json::encode($this->options['id'])."].on('blur', function() {CKEDITOR.instances[".Json::encode($this->options['id'])."].updateElement();})}");
$this->editorOptions['on']['instanceReady'] = new JsExpression("function( ev ){".implode(' ', $js)."}");

if($this->_inline){
$JavaScript = "CKEDITOR.inline(";
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@
},
"require": {
"yiisoft/yii2": "*"
}
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
29 changes: 29 additions & 0 deletions editor/js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
if (typeof mihaildev == "undefined" || !mihaildev) {
var mihaildev = {};
}

mihaildev.ckEditor = {
registerOnChange: function(id){
CKEDITOR.instances[id] && CKEDITOR.instances[id].on('change', function () {
CKEDITOR.instances[id].updateElement();
jQuery('#' + id).trigger('change');
return false;
});
},
isRegisteredCsrf: false,
registerCsrf: function(){
if(this.isRegisteredCsrf)
return;

this.isRegisteredCsrf = true;

yii & jQuery(document).off('click', '.cke_dialog_tabs a:eq(2)').on('click', '.cke_dialog_tabs a:eq(2)', function () {
var form = jQuery('.cke_dialog_ui_input_file iframe').contents().find('form');
var csrfName = yii.getCsrfParam();
if (!form.find('input[name=' + csrfName + ']').length) {
var csrfTokenInput = jQuery('<input/>').attr({'type': 'hidden', 'name': csrfName}).val(yii.getCsrfToken());
form.append(csrfTokenInput);
}
});
}
};

0 comments on commit d20aa7f

Please sign in to comment.