-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artur Gajewski
committed
Sep 18, 2012
0 parents
commit 24f4e85
Showing
11 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace ContentEditable; | ||
|
||
use ContentEditable\View\Helper\ContentEdit; | ||
|
||
class Module | ||
{ | ||
public function getAutoloaderConfig() | ||
{ | ||
return array( | ||
'Zend\Loader\ClassMapAutoloader' => array( | ||
__DIR__ . '/autoload_classmap.php', | ||
), | ||
'Zend\Loader\StandardAutoloader' => array( | ||
'namespaces' => array( | ||
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function getServiceConfig() | ||
{ | ||
return array( | ||
'factories' => array( | ||
'ContentEditable' => 'ContentEditable\Service\Factory', | ||
) | ||
); | ||
} | ||
|
||
public function getConfig() | ||
{ | ||
return include __DIR__ . '/config/module.config.php'; | ||
} | ||
|
||
public function getViewHelperConfig() | ||
{ | ||
return array( | ||
'factories' => array( | ||
'getContentEditableFile' => function ($sm) { | ||
$locator = $sm->getServiceLocator(); | ||
$config = $locator->get('Configuration'); | ||
$params = $config['ContentEditable']['params']; | ||
|
||
$viewHelper = new View\Helper\ContentEditable(); | ||
$viewHelper->setService($locator->get('ContentEditable')); | ||
$viewHelper->setParams($params); | ||
|
||
return $viewHelper; | ||
}, | ||
), | ||
); | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# ContentEditable module for Zend Framework 2 | ||
|
||
This module provides a way to make any HTML tag's inner content editable in TEXTAREA editor. | ||
|
||
|
||
Requirements: | ||
|
||
- PHP 5.3 | ||
- Zend Framework 2 | ||
- rwoverdijk/assetmanager @ [https://github.com/RWOverdijk/AssetManager](https://github.com/RWOverdijk/AssetManager) | ||
|
||
See [https://github.com/artur-gajewski/ContentEditable](https://github.com/artur-gajewski/ContentEditable) | ||
|
||
@Author: Artur Gajewski | ||
|
||
|
||
## Installation with Composer | ||
|
||
Go to your project directory and add the following line to "require" list in composer.json file: | ||
|
||
```php | ||
"artur-gajewski/content-editable": "dev-master" | ||
``` | ||
|
||
Now run the Composer: | ||
|
||
```php | ||
php composer.phar install | ||
``` | ||
|
||
Then add 'ContentEditable' into the Module array in APPLICATION_ROOT/config/application.config.php | ||
|
||
```php | ||
<?php | ||
return array( | ||
'modules' => array( | ||
... | ||
'ContentEditable', | ||
... | ||
), | ||
); | ||
``` | ||
|
||
|
||
## Adding JS and CSS files to your layout script | ||
|
||
ContentEditable uses it's own Javascript and CSS files to generate dynamic edit capabilities within your view script. | ||
|
||
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'); | ||
``` | ||
|
||
|
||
## Making your website editable | ||
|
||
Now all you have to do, is to add a CSS style class to all tags you wish to become editable. You will also need to include a path in the data-url attribute | ||
to where the content needs to be sent in order to save it in the database. | ||
|
||
```php | ||
<div class="editable" data-url="/article/update/1432">This is my content</div> | ||
``` | ||
|
||
When you load the page and hover your mouse on top of the "This is my content" text, you will see the cursor changes to a pointer. Now if you click on this text, it will become a TEXTAREA with raw HTML code inside. Go ahead and edit the contents and then click somewhere outside the TEXTAREA. You will be requested to confirm data update. | ||
|
||
Once you accept the modifications you have made, a request will be made to the given data-url with a parameter "editable_content", which ofcourse contains the contents of the edited data. | ||
|
||
|
||
## Questions or comments? | ||
|
||
Feel free to email me with any questions or comments about this module | ||
|
||
[[email protected]](mailto:[email protected]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
return array(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "artur-gajewski/content-editable", | ||
"description": "This module provides a way to make any HTML tag's inner content editable in TEXTAREA editor.", | ||
"type": "module", | ||
"keywords": [ | ||
"zf2", | ||
"content", | ||
"edit" | ||
], | ||
"homepage": "https://github.com/artur-gajewski/ContentEditable", | ||
"authors": [ | ||
{ | ||
"name": "Artur Gajewski", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/artur-gajewski" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=5.3.3", | ||
"zendframework/zendframework": "dev-master", | ||
"rwoverdijk/assetmanager": "dev-master" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"ContentEditable": "src/" | ||
}, | ||
"classmap": [ | ||
"./Module.php" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace ContentEditable; | ||
|
||
return array( | ||
__NAMESPACE__ => array( | ||
'params' => array( | ||
'js_source_path' => '/js/ContentEditable.js', | ||
'css_source_path' => '/css/ContentEditable.css' | ||
), | ||
), | ||
'asset_manager' => array( | ||
'resolver_configs' => array( | ||
'paths' => array( | ||
'ContentEdit' => __DIR__ . '/../public', | ||
), | ||
), | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
textarea.editabler { | ||
width: 100%; | ||
} | ||
|
||
.editable { | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
$(document).ready(function() { | ||
|
||
$(".editable").click(divClicked); | ||
|
||
var attrs = []; | ||
var attributes = []; | ||
|
||
var attrsHtml = ""; | ||
var editableUrl = ""; | ||
var editableTag = ""; | ||
var editableOriginal = ""; | ||
|
||
function divClicked() { | ||
var divHtml = $(this).html(); | ||
var height = $(this).height(); | ||
|
||
editableTag = this.nodeName.toLowerCase(); | ||
attributes = $(this).prop("attributes"); | ||
|
||
$.each(attributes, function() { | ||
if (this.name == 'data-url') { | ||
editableUrl = this.value; | ||
} | ||
attrs.push(this.name + '="' + this.value +'"'); | ||
}); | ||
|
||
if (!editableUrl) { | ||
alert("Attribute data-url is missing!"); | ||
return; | ||
} | ||
|
||
attrsHtml = attrs.join(' '); | ||
|
||
var editableText = $("<textarea class=\"editabler\" style=\"height: " + height + "px\"/>"); | ||
editableText.val(divHtml); | ||
editableOriginal = divHtml; | ||
|
||
$(this).replaceWith(editableText); | ||
editableText.focus(); | ||
editableText.blur(editableTextBlurred); | ||
} | ||
|
||
function editableTextBlurred() { | ||
var html = $(this).val(); | ||
var viewableText = $("<" + editableTag + " " + attrsHtml + ">"); | ||
|
||
var answer = confirm("Do you really want to update this content?") | ||
if (answer){ | ||
viewableText.html(html); | ||
$.ajax({ | ||
type: 'POST', | ||
url: editableUrl, | ||
data: "editable_content=" + html, | ||
error: function(XMLHttpRequest, textStatus, errorThrown) { | ||
alert("Content has not been saved due to an error: " + errorThrown); | ||
} | ||
}); | ||
} else { | ||
viewableText.html(editableOriginal); | ||
} | ||
|
||
$(this).replaceWith(viewableText); | ||
viewableText.click(divClicked); | ||
} | ||
|
||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace ContentEditable; | ||
|
||
class Manager | ||
{ | ||
/** | ||
* @var Array | ||
*/ | ||
protected $params; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $cache; | ||
|
||
/** | ||
* Set the Module specific configuration parameters | ||
* | ||
* @param Array $params | ||
*/ | ||
public function __construct($params) { | ||
$this->params = $params; | ||
} | ||
|
||
public function get($type) | ||
{ | ||
if ($type == 'css') { | ||
return $this->getCss(); | ||
} | ||
if ($type == 'js') { | ||
return $this->getJavascript(); | ||
} | ||
} | ||
|
||
/** | ||
* Generate JS inclusion HTML code | ||
*/ | ||
public function getJavascript() | ||
{ | ||
$link = '<script type="text/javascript" src="' . $this->params['js_source_path'] . '"></script>'; | ||
return $link; | ||
} | ||
|
||
/** | ||
* Generate CSS inclusion HTML code | ||
* | ||
* @param string $media | ||
* @return string | ||
*/ | ||
public function getCss($media = 'screen') | ||
{ | ||
$link = '<link href="' . $this->params['css_source_path'] . '" media="'. $media .'" rel="stylesheet" type="text/css" />'; | ||
return $link; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace ContentEditable\Service; | ||
|
||
use Zend\ServiceManager\FactoryInterface, | ||
Zend\ServiceManager\ServiceLocatorInterface, | ||
ContentEditable\Manager; | ||
|
||
/** | ||
* ContentEdit service manager factory | ||
*/ | ||
class Factory implements FactoryInterface | ||
{ | ||
/** | ||
* Factory method for ContentEditable Manager service | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @return ContentEditable\Manager | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$config = $serviceLocator->get('Configuration'); | ||
$params = $config['ContentEditable']['params']; | ||
|
||
$manager = new Manager($params); | ||
return $manager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace ContentEditable; | ||
|
||
class Version | ||
{ | ||
const VERSION = '0.0.1'; | ||
} |
Oops, something went wrong.