Commit 2a7fc027 by Frédéric

Plugin

parent 15d60c8f
.idea/ .DS_*
config.yml
composer.lock
vendor/
tests/tmp/
.idea
#### Installation :
Go to extensions dir
Add this to composer.json in repositories part
```
{
"type": "composer",
"url": "https://packages.lab.appolo.fr/"
},
```
Run
> composer require appolo/bolt-extension-ckeditor-embed-plugins
{
"name": "appolo/bolt-extension-ckeditor-embed-plugins",
"description": "",
"type": "bolt-extension",
"keywords": [
],
"version": "0.0.1",
"require": {
"bolt/bolt": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.7"
},
"license": "MIT",
"authors": [
{
"name": "Appolo",
"email": "contact@appolo.fr"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Bolt\\Extension\\Appolo\\CkEditorEmbedPlugins\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Bolt\\Extension\\Appolo\\CkEditorEmbedPlugins\\Tests\\": "tests",
"Bolt\\Tests\\": "vendor/bolt/bolt/tests/phpunit/unit/"
}
},
"extra": {
"bolt-assets": "web",
"bolt-class": "Bolt\\Extension\\Appolo\\CkEditorEmbedPlugins\\CkEditorEmbedPluginsExtension"
}
}
# Default path
default_file_path: "files"
<?php
namespace Bolt\Extension\Appolo\CkEditorEmbedPlugins;
use Bolt\Asset\File\JavaScript;
use Bolt\Controller\Zone;
use Bolt\Extension\SimpleExtension;
/**
* ExtensionName extension class.
*
* @author Your Name <you@example.com>
*/
class CkEditorEmbedPluginsExtension extends SimpleExtension
{
/**
* @return array
*/
protected function registerAssets()
{
return [
JavaScript::create()
->setFileName('backend/js/backend.js')
->setLate(true)
->setPriority(5)
->setZone(Zone::BACKEND)
];
}
}
$( document ).ready(function() {
$('.filebrowser').each(function (index, value) {
$(this).click(function (e) {
var $that = $(this);
$.get('/bolt/directory/getdirectory/', function( data ) {
if(data.directoryName) {
var name = $that.attr('name');
$that.hide();
$that.parent().append('<div class="'+name+'"></div>');
var $tree = $('.'+name)
.on('loaded.jstree', function() {
var item = getItemFromPath($that.val(), data);
$tree.jstree('select_node', item.id);
})
.jstree(
{
'core' : {
'data' : data.directoryName
}
}
);
$(document).on('dblclick', '.'+name+' a',function (e) {
var node = $(e.target).closest("li");
var id = node[0].id;
var item = getItemFromId(id, data);
if(item.path) {
$that.val(item.path);
}
$('.'+name).remove();
$that.show();
});
}
});
});
});
/**
* Get Item from ID
* @param id
* @param data
* @returns {{}}
*/
function getItemFromId(id, data) {
var item = {};
for(var index in data.directoryName) {
if(data.directoryName[index].id == id) {
item = data.directoryName[index];
}
}
return item;
}
/**
* Get Item from Path
* @param path
* @param data
* @returns {{}}
*/
function getItemFromPath(path, data) {
var item = {};
for(var index in data.directoryName) {
if(data.directoryName[index].path == path) {
item = data.directoryName[index];
}
}
return item;
}
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment