@laimoon/callback v2.0.5
Laimoon Callback UI Package
This JS package provides an easy way to integrate callback popup inside any laimoon's project.
The back-end logic is handled by profiles.laimoon.com
.
The code structure
In this project, we use pure JavaScript to minimize the loading time without any additional load with just ~8k gzip in the production
The idea behind the code is that we can inject the course callback popup anywhere in any project regardless of the technology behind it.
The code behind the actual HTML template is written inside dom.js
file with help of some useful selectors and classes to fetch and modify elements easily.
The core logic of rendering the callback popup is written inside LaimoonCallback.js
class.
This class is exposed globally once the package is loaded to any project such as courses or careerguide.
Using the exposed object LaimoonCallback
we can easily control the display and other configurations of the popup.
For example, we use the method open
to display the popup with different configurations by passing the config as a parameter:
LaimoonCallback.open({
courseId: 'Required | Number',
title: 'Required | String',
description: 'Required | String',
classification: 'Required | ENUM | booking, demo, recording, video, info',
trainigOptions: 'Optional | Array of JSON',
trainigOptionTitle: 'Optional | String',
trainigOptionsDefault: 'Optional | ENUM | virtaul, blended',
feedbackTitle: 'Optional | String',
feedbackDescription: 'Optional | String',
callback: 'Optional | Function'
});
Additionally, we use some useful utilities inside utils.js
file such as email and phone validation.
Finally, once a user submitted the form, the popup status will change to be submitted and display the feedbackTitle
and feedbackDescription
also will trigger the callback function if provided in the config.
Get Started
- Install the pacakge via
npm
:
npm i @laimoon/callback --save
- Install webpack or any bundler you want, I suggest using Laravel Mix since it wraps webpack's complixity and let you focus on work:
npm install cross-env laravel-mix --save-dev
cp node_modules/laravel-mix/setup/webpack.mix.js ./
- Update your
webpack.mix.js
to the following:
const mix = require('laravel-mix');
mix.js('src/js/callback.js','webroot/js');
- Create a JS file under
src/js/callback.js
and put the following:
require('@laimoon/callback');
- Add the following scrips into your
package.json
:
{
...
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
...
}
- Compile your JS file
callback.js
for production:
npm run prod
- Add the generated
webroot/js/callback.js
into your HTML and then add the following VueJs component into the first element od the body:
<body>
<div id="app">
<laimoon-callback></laimoon-callback>
</div>
...
</body>
- Once done, you'll have a global object
LaimoonCallback
you can consume to open and close the callback popup whenever you want:
The available methods:
LaimoonCallback.open(); // will open the login UI
LaimoonCallback.close(); // will close the current open callback form popup
Development
This projects uses webpack with the help of Laravel mix, you can refer to webpack config inside webpack.mix.js
for more details.
To rebuild the project during development with watcher:
npm run watch
To rebuild the project with minification for production:
npm run prod
To test your work locally while developing it, you can link the package using npm link:
This step is helpful instead of pushing your developemnt work to npm and then pull it back to any project so that you can save time.
- In thus repo, run:
npm link
- In your test projects, use:
npm link laimoon-callback
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago