Commit eeee5653 authored by Thomas SECHER's avatar Thomas SECHER
Browse files

Initial commit

parents
libraries/assets/local.config.js
**/node_modules
Trigger API
/**
* @file
* Defines dialog for TriggerApiCKeditorPlugin CKEditor plugin.
*/
(function (Drupal) {
'use strict';
// Dialog definition.
CKEDITOR.dialog.add('ckeditorPluginDialog', function (editor) {
return {
// Basic properties of the dialog window: title, minimum size.
title: Drupal.t('Abbreviation properties'),
minWidth: 400,
minHeight: 150,
// Dialog window content definition.
contents: [
{
// Definition of the settings dialog tab.
id: 'tab-settings',
label: 'Settings',
// The tab content.
elements: [
{
// Text input field for the abbreviation text.
type: 'text',
id: 'abbr',
label: Drupal.t('Abbreviation'),
// Validation checking whether the field is not empty.
validate: CKEDITOR.dialog.validate.notEmpty(Drupal.t('Abbreviation field cannot be empty.'))
},
{
// Text input field for the abbreviation text.
type: 'text',
id: 'abbr',
label: Drupal.t('Abbreviation'),
// Validation checking whether the field is not empty.
validate: CKEDITOR.dialog.validate.notEmpty(Drupal.t('Abbreviation field cannot be empty.'))
},
{
// Text input field for the abbreviation title (explanation).
type: 'text',
id: 'title',
label: Drupal.t('Explanation'),
validate: CKEDITOR.dialog.validate.notEmpty(Drupal.t('Explanation field cannot be empty.'))
}
]
}
],
// This method is invoked once a user clicks the OK button, confirming the
// dialog.
onOk: function () {
// The context of this function is the dialog object itself.
// See http://docs.ckeditor.com/#!/api/CKEDITOR.dialog.
var dialog = this;
// Create a new <abbr> element.
var abbr = editor.document.createElement('abbr');
// Set element attribute and text by getting the defined field values.
abbr.setAttribute('title', dialog.getValueOf('tab-settings', 'title'));
abbr.setText(dialog.getValueOf('tab-settings', 'abbr'));
// Finally, insert the element into the editor at the caret position.
editor.insertElement(abbr);
}
};
});
} (Drupal));
/**
* @file
* TriggerApiCKeditorPlugin CKEditor plugin.
*
* Basic plugin inserting abbreviation elements into the CKEditor editing area.
*
* @DCG The code is based on an example from CKEditor Plugin SDK tutorial.
*
* @see http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1
*/
(function (Drupal) {
'use strict';
CKEDITOR.plugins.add('trigger_api_ckeditor_plugin', {
// Register the icons.
icons: 'trigger-api-plugin',
// The plugin initialization logic goes inside this method.
init: function (editor) {
// Add custom command.
// @todo
// editor.addCommand('triggerApiPlugin', {
// allowedContent:
// 'a',
// modes: { wysiwyg: 1 },
// canUndo: true,
// exec(editor, data) {
// const dialogSettings = {
// title: data.dialogTitle,
// dialogClass: 'editor-image-dialog',
// };
// Drupal.ckeditor.openDialog(
// editor,
// Drupal.url("/trigger-api/trigger-api-ckeditor"),
// data.existingValues,
// data.saveCallback,
// dialogSettings,
// );
// },
// });
// Create a toolbar button that executes the above command.
editor.ui.addButton('trigger-api-plugin', {
// The text part of the button (if available) and the tooltip.
label: Drupal.t('Insert Trigger API data'),
// The command to execute on click.
command: 'triggerApiPlugin',
// The button placement in the toolbar (toolbar group name).
toolbar: 'insert'
});
}
});
} (Drupal));
/**
* Vous pouvez surcharger ici la configuration par défaut de chaque tache.
*/
module.exports = {
"build": {
"src": "src/",
"dev": "../dev",
"prod": "../dist"
},
// "scripts": {
// "ext": "{js,ts}",
// "src": "js/*.",
// "dest": "",
// "watch": "js/**/*."
// }
};
node_modules/gulp/bin/gulp.js
\ No newline at end of file
/**
* Load toutes les taches par défaut présente dans lycanthrop_gulp/tasks/*.js
* @type {TaskLoaderClass}
*/
const taskLoader = require('bim-gulp/utils/TaskLoader');
// Load les taches par défaut
taskLoader.loadDefaultTasks(exports, ['scripts']);
// Définition de la tache par défaut :
exports.default = exports.watch
// Load les taches custom
taskLoader.loadTasks('./tasks', exports);
This diff is collapsed.
{
"name": "assets",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/preset-env": "^7.15.6",
"babel-loader": "^8.2.2",
"bim-gulp": "^0.0.5",
"browser-sync": "^2.27.5",
"piped-webpack": "^1.4.1",
"ts-loader": "^9.2.6"
}
}
import {TriggerApi} from "./utils/trigger-api";
(function (Drupal, DrupalSettings) { // closure
'use strict';
// AJax command
Drupal.AjaxCommands.prototype.TriggerApiCommand = (ajax, response, status ) => {
TriggerApi.dispatch(response.type, response.data);
}
// Behaviros.
Drupal.behaviors.trigger_api = TriggerApi;
}(Drupal, drupalSettings));
class TriggerApiClass {
attach(context, settings) {
// Trigger from settings.
if (context === document) {
this.triggerFromSettings(settings);
}
// Trigger from context
this.triggerFromContext(context);
}
/**
* Return the event.
*
* @param type
* @param data
* @return {Event}
*/
getEvent(type, data) {
const event = new Event(type);
event.data = data;
return event;
}
/**
* Trigger events from settings.
*
* @param settings
*/
triggerFromSettings(settings) {
if (settings.trigger_api) {
settings.trigger_api.forEach(item => {
this.dispatch(item.type, item.data)
})
}
}
/**
* Trigger from context.
*/
triggerFromContext(context) {
context.querySelectorAll('[data-trigger-api-on]').forEach(item => {
try{
const type = item.getAttribute('data-trigger-api-type'),
eventType = item.getAttribute('data-trigger-api-on'),
data = JSON.parse(item.getAttribute('data-trigger-api-data'));
switch (eventType) {
case 'appear':
this.dispatch(type, data)
break;
default:
item.addEventListener(eventType, () => {
this.dispatch(type, data)
});
break;
}
}
catch(e){
}
})
}
/**
* Dispatch event.
*
* @param type
* @param data
*/
dispatch(type, data) {
const event = this.getEvent(type, data)
document.dispatchEvent(event)
}
}
export const TriggerApi = new TriggerApiClass();
const {series, parallel} = require('gulp')
const {productionMode} = require('bim-gulp/tasks/build/productionMode')
const {clean} = require('bim-gulp/tasks/clean/clean')
const {scripts} = require('bim-gulp/tasks/scripts/scripts')
// Build en mode dev.
exports.build = series(
clean,
// Scripts et css sont indépendants
scripts,
);
// Build en mode production.
exports.production = series(productionMode, exports.build)
// Alias
exports.prod = exports.production
exports.beforeWatch = exports.build
// Default conf
exports.defaultConfiguration = {
'build': {
// Répertoire des sources comprenant les bundles
src: 'bundles/',
// Répertoire de destination des builds
dev: '../dev',
// Répertoire de destination de prod.
prod: '../dist',
}
}
\ No newline at end of file
{
"compilerOptions": {
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"allowJs": true
}
}
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/trigger_api/js/main.js":
/*!************************************!*\
!*** ./src/trigger_api/js/main.js ***!
\************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _utils_trigger_api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/trigger-api */ \"./src/trigger_api/js/utils/trigger-api.js\");\n\n\n(function (Drupal, DrupalSettings) {\n // closure\n 'use strict'; // AJax command\n\n Drupal.AjaxCommands.prototype.TriggerApiCommand = function (ajax, response, status) {\n _utils_trigger_api__WEBPACK_IMPORTED_MODULE_0__.TriggerApi.dispatch(response.type, response.data);\n }; // Behaviros.\n\n\n Drupal.behaviors.trigger_api = _utils_trigger_api__WEBPACK_IMPORTED_MODULE_0__.TriggerApi;\n})(Drupal, drupalSettings);\n\n//# sourceURL=webpack://assets/./src/trigger_api/js/main.js?");
/***/ }),
/***/ "./src/trigger_api/js/utils/trigger-api.js":
/*!*************************************************!*\
!*** ./src/trigger_api/js/utils/trigger-api.js ***!
\*************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"TriggerApi\": () => (/* binding */ TriggerApi)\n/* harmony export */ });\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar TriggerApiClass = /*#__PURE__*/function () {\n function TriggerApiClass() {\n _classCallCheck(this, TriggerApiClass);\n }\n\n _createClass(TriggerApiClass, [{\n key: \"attach\",\n value: function attach(context, settings) {\n // Trigger from settings.\n if (context === document) {\n this.triggerFromSettings(settings);\n } // Trigger from context\n\n\n this.triggerFromContext(context);\n }\n /**\n * Return the event.\n *\n * @param type\n * @param data\n * @return {Event}\n */\n\n }, {\n key: \"getEvent\",\n value: function getEvent(type, data) {\n var event = new Event(type);\n event.data = data;\n return event;\n }\n /**\n * Trigger events from settings.\n *\n * @param settings\n */\n\n }, {\n key: \"triggerFromSettings\",\n value: function triggerFromSettings(settings) {\n var _this = this;\n\n if (settings.trigger_api) {\n settings.trigger_api.forEach(function (item) {\n _this.dispatch(item.type, item.data);\n });\n }\n }\n /**\n * Trigger from context.\n */\n\n }, {\n key: \"triggerFromContext\",\n value: function triggerFromContext(context) {\n var _this2 = this;\n\n context.querySelectorAll('[data-trigger-api-on]').forEach(function (item) {\n try {\n var type = item.getAttribute('data-trigger-api-type'),\n eventType = item.getAttribute('data-trigger-api-on'),\n data = JSON.parse(item.getAttribute('data-trigger-api-data'));\n\n switch (eventType) {\n case 'appear':\n _this2.dispatch(type, data);\n\n break;\n\n default:\n item.addEventListener(eventType, function () {\n _this2.dispatch(type, data);\n });\n break;\n }\n } catch (e) {}\n });\n }\n /**\n * Dispatch event.\n *\n * @param type\n * @param data\n */\n\n }, {\n key: \"dispatch\",\n value: function dispatch(type, data) {\n var event = this.getEvent(type, data);\n document.dispatchEvent(event);\n }\n }]);\n\n return TriggerApiClass;\n}();\n\nvar TriggerApi = new TriggerApiClass();\n\n//# sourceURL=webpack://assets/./src/trigger_api/js/utils/trigger-api.js?");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = __webpack_require__("./src/trigger_api/js/main.js");
/******/
/******/ })()
;
\ No newline at end of file
(()=>{"use strict";function t(t,e){for(var a=0;a<e.length;a++){var r=e[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var e=new(function(){function e(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e)}var a,r;return a=e,(r=[{key:"attach",value:function(t,e){t===document&&this.triggerFromSettings(e),this.triggerFromContext(t)}},{key:"getEvent",value:function(t,e){var a=new Event(t);return a.data=e,a}},{key:"triggerFromSettings",value:function(t){var e=this;t.trigger_api&&t.trigger_api.forEach((function(t){e.dispatch(t.type,t.data)}))}},{key:"triggerFromContext",value:function(t){var e=this;t.querySelectorAll("[data-trigger-api-on]").forEach((function(t){try{var a=t.getAttribute("data-trigger-api-type"),r=t.getAttribute("data-trigger-api-on"),i=JSON.parse(t.getAttribute("data-trigger-api-data"));"appear"===r?e.dispatch(a,i):t.addEventListener(r,(function(){e.dispatch(a,i)}))}catch(t){}}))}},{key:"dispatch",value:function(t,e){var a=this.getEvent(t,e);document.dispatchEvent(a)}}])&&t(a.prototype,r),e}());!function(t,a){t.AjaxCommands.prototype.TriggerApiCommand=function(t,a,r){e.dispatch(a.type,a.data)},t.behaviors.trigger_api=e}(Drupal,drupalSettings)})();
\ No newline at end of file
<?php
namespace Drupal\trigger_api\Ajax;
use Drupal\Core\Ajax\CommandInterface;
use Drupal\trigger_api\Data\TriggerQueueDataInterface;
class TriggerApiCommand implements CommandInterface {
/**
* Trigger queue data.
*
* @var \Drupal\trigger_api\Data\TriggerQueueDataInterface
*/
protected TriggerQueueDataInterface $triggerQueueData;
/**
* @param \Drupal\trigger_api\Data\TriggerQueueDataInterface $triggerQueueData
*/
public function __construct(TriggerQueueDataInterface $triggerQueueData) {
$this->triggerQueueData = $triggerQueueData;
}
/**
* {@inheritdoc}
*/
public function render() {
return [
'command' => 'TriggerApiCommand',
'type' => $this->triggerQueueData->getType(),
'data' => $this->triggerQueueData->getRawData(),
];
}
}
<?php
namespace Drupal\trigger_api\Data;
use Drupal\Component\Serialization\Json;
/**
* Trigger data.
*/
class TriggerQueueData implements TriggerQueueDataInterface {
/**
* TYpe.
*
* @var string
*/
protected string $type;
/**
* Data.
*
* @var array
*/
protected array $data;
/**
* @param string $type
* The type of trigger.
* @param array $data
* The data.
*/
public function __construct(string $type, array $data) {
$this->type = $type;
$this->data = $data;
}
/**
* {@inheritdoc}
*/
public function getType(): string {
return $this->type;
}
/**
* {@inheritdoc}
*/
public function getRawData(): array {
return $this->data;
}
/**
* {@inheritdoc}
*/
public function getSerializableData(): array {
// Trigger json encode exception.
Json::encode($this->data);
return $this->data;
}
}
<?php
namespace Drupal\trigger_api\Data;
/**
* Describe the data stocked in triggered queue.
*/
interface TriggerQueueDataInterface {
/**
* Return the type.
*
* @return string
* The type.
*/
public function getType(): string;
/**
* Return the raw data.
*
* @return array
* The data.
*/
public function getRawData(): array;
/**
* Return the serialized data.
*
* @return string
*/
public function getSerializableData(): array;
}
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