Skip to content

Commit

Permalink
Merge pull request #10 from spekary/master
Browse files Browse the repository at this point in the history
bugfix-Configuration
  • Loading branch information
spekary committed Jul 29, 2016
2 parents 0a84db7 + 1bdf756 commit c2ad555
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
}
},
"extra": {
"examples": ["ckeditor.php"]
"examples": ["ckeditor.php", "ckeditor2.php"]
}
}
34 changes: 34 additions & 0 deletions examples/ckeditor2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require('../../../framework/qcubed.inc.php');

use QCubed\Plugin\QCKEditor;

/**
* Class SampleForm2
*
* This example demonstrates how to call an initialization function to customize the ck editor
*/
class SampleForm2 extends QForm {
protected $txtEditor;
protected $btnSubmit;
protected $pnlResult;

protected function Form_Create() {
$this->txtEditor = new QCKEditor($this);
$this->txtEditor->Text = '<b>Something</b> to start with.';
$this->txtEditor->Configuration = 'ckConfig';

$this->btnSubmit = new QButton($this);
$this->btnSubmit->Text = "Submit";
$this->btnSubmit->AddAction(new QClickEvent(), new QAjaxAction('submit_click'));

$this->pnlResult = new QPanel($this);
$this->pnlResult->HtmlEntities = true;
}

protected function submit_click($strFormId, $strControlId, $param) {
$this->pnlResult->Text = $this->txtEditor->Text;
}
}

SampleForm2::Run('SampleForm2');
25 changes: 25 additions & 0 deletions examples/ckeditor2.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php require(__DOCROOT__ . __EXAMPLES__ . '/includes/header.inc.php'); ?>
<script>
ckConfig = {
language: 'fr',
uiColor: '#9AB8F3'
};
</script>


<?php $this->RenderBegin(); ?>

<div class="instructions">
<h1 class="instruction_title">QCKEditor: Implementation of the CKEditor HTML editor.</h1>
<p>
<b>QCKEditor</b> implements the <a href="http://ckeditor.com">CKEditor HTML editor</a>. It allows you
to create a text editing block with full HTML editing capabilities. The text returned from it is HTML.
</p>
<?php $this->txtEditor->Render(); ?>
<?php $this->btnSubmit->Render(); ?>
<h3>The HTML you typed:</h3>
<?php $this->pnlResult->Render(); ?>
</div>

<?php $this->RenderEnd(); ?>
<?php require(__DOCROOT__ . __EXAMPLES__ . '/includes/footer.inc.php'); ?>
15 changes: 14 additions & 1 deletion includes/QCKEditorBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class QCKEditorBase extends \QTextBoxBase {

protected $strJsReadyFunc = 'function(){}';
protected $strConfiguration = '{}';

public function __construct($objParentObject, $strControlId = null) {
parent::__construct($objParentObject, $strControlId);
Expand Down Expand Up @@ -42,7 +43,7 @@ public function GetControlJavaScript() {
$strReadyFunc = $this->strJsReadyFunc;
}
$strJs = "function() {qcubed.qckeditor(this, '{$strFormId}', '{$strControlId}', {$strReadyFunc});}";
return sprintf('jQuery("#%s").%s(%s)', $this->getJqControlId(), $this->getJqSetupFunction(), $strJs);
return sprintf('jQuery("#%s").%s(%s, %s)', $this->getJqControlId(), $this->getJqSetupFunction(), $strJs, $this->strConfiguration);
}

public function GetEndScript() {
Expand All @@ -65,6 +66,18 @@ public function __set($strName, $mixValue) {
}
break;

case "Configuration":
// The configuration string. Could be a name of an object, or a javascript object (sourrounded by braces {})
try {
$this->strConfiguration = \QType::Cast($mixValue, \QType::String);
break;
} catch (QInvalidCastException $objExc) {
$objExc->IncrementOffset();
throw $objExc;
}
break;


default:
try {
parent::__set($strName, $mixValue);
Expand Down

0 comments on commit c2ad555

Please sign in to comment.