Skip to content

Commit

Permalink
Fixed modal error handling and added some context to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Gajewski committed Sep 21, 2012
1 parent 1a16b96 commit 4e468e3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getViewHelperConfig()
{
return array(
'factories' => array(
'getContentEditableFile' => function ($sm) {
'getContentEditableFiles' => function ($sm) {
$locator = $sm->getServiceLocator();
$config = $locator->get('Configuration');
$params = $config['ContentEditable']['params'];
Expand Down
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See [https://github.com/artur-gajewski/ContentEditable](https://github.com/artur

You can go ahead and try the live demo of ContentEditable module at [http://arturgajewski.com/cedemo](http://arturgajewski.com/cedemo)

Click on any of the three columns on the front page to edit their content. Once done, click outside the div to get confirmation to save modifications.
Click on any of the three columns on the front page to edit their content. Once done, click outside the div to get confirmation to save modifications. Third column will give an error status since it has a data-url that is not available.

Please note: This is a demo, no data is actually saved and will revert to original content on page reload.

Expand Down Expand Up @@ -64,8 +64,30 @@ ContentEditable uses it's own Javascript and CSS files to generate dynamic edit
In order to get ContentEditable working, you need to include these files where you include all your Javascript and CSS files.

```php
echo $this->getContentEditableFile('js');
echo $this->getContentEditableFile('css');
echo $this->getContentEditableFiles('js');
echo $this->getContentEditableFiles('css');
```

if you want to include bundled jQuery and jQuery-UI, you need to add a boolean parameter like so:

```php
echo $this->getContentEditableFiles('js', true);
echo $this->getContentEditableFiles('css', true);
```

If you want to override the bundled package with newer version, you can override the path to Javascript and CSS files in module.config.php file:

```php
'params' => array(
// ContentEditable related
'js_source_path' => '/js/ContentEditable.js',
'css_source_path' => '/css/ContentEditable.css',

// jQuery related
'jquery_js_source_path' => '/js/jquery-1.8.0.min.js',
'jquery-ui_js_source_path' => '/js/jquery-ui-1.8.23.custom.min.js',
'jquery_ui_css_path' => '/css/ui-lightness/jquery-ui-1.8.23.custom.css',
),
```


Expand Down Expand Up @@ -185,11 +207,6 @@ TEXTAREA is core HTML and provides a light and easy way to edit HTML code. Conte
My plans are to add such capability is a future version. Stay tuned!


###5. Are there any other future plans?

Yes. I am planning on adding preview functionality so that you can preview the content before saving it. Also there will be nicer looking styles for the TEXTAREA editor. I will also implement a better looking modal for confirmation and messages instead of alert function.


## Questions or comments?

Feel free to email me with any questions or comments about this module
Expand Down
5 changes: 3 additions & 2 deletions public/js/ContentEditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ $(document).ready(function() {
function editableTextBlurred() {
var html = $(this).val();
var viewableText = $("<" + CE_editableTag + " " + CE_attrsHtml + ">");
var error = false;

$('#notification').find('p').html("Please select action:");
$( "#notification" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Save": function() {
"Save": function(fn) {
viewableText.html(html);
$.ajax({
type: 'POST',
url: CE_editableUrl,
data: "editable_content=" + html,
success: function() {
$(this).dialog( "close" );
$('#notification').dialog('close');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#notification').find('p').html("There was an error: " + errorThrown);
Expand Down
26 changes: 13 additions & 13 deletions src/ContentEditable/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function __construct($params) {

public function get($type, $option)
{
if ($type == 'css') {
return $this->getCss($option);
}
elseif ($type == 'js') {
if ($type == 'js') {
return $this->getJavascript($option);
}
elseif ($type == 'css') {
return $this->getCss($option);
}
elseif ($type == 'dialog') {
return $this->getContent($option);
}
Expand All @@ -44,23 +44,23 @@ public function getJavascript($includeBundledJquery = false)
$links = array();
if ($includeBundledJquery === true) {
$links[] = '<script type="text/javascript" src="' . $this->params['jquery_js_source_path'] . '"></script>';
$links[] = '<script type="text/javascript" src="' . $this->params['jquery-ui_js_source_path'] . '"></script>';
}
$links[] = '<script type="text/javascript" src="' . $this->params['jquery-ui_js_source_path'] . '"></script>';
$links[] = '<script type="text/javascript" src="' . $this->params['js_source_path'] . '"></script>';


return implode("", $links);
}

/**
* Generate CSS inclusion HTML code
*
* @param string $media
* @return string
* Generate CSS inclusion CSS code
*/
public function getCss($media = 'screen')
public function getCss($includeBundledJquery = false)
{
$links = array();
$links[] = '<link href="' . $this->params['css_source_path'] . '" media="'. $media .'" rel="stylesheet" type="text/css" />';
$links[] = '<link href="' . $this->params['jquery_ui_css_path'] . '" rel="stylesheet" type="text/css" />';
$links[] = '<link href="' . $this->params['css_source_path'] . '" rel="stylesheet" type="text/css" />';
if ($includeBundledJquery === true) {
$links[] = '<link href="' . $this->params['jquery_ui_css_path'] . '" rel="stylesheet" type="text/css" />';
}

return implode("", $links);
}
Expand Down

0 comments on commit 4e468e3

Please sign in to comment.