mirror of
https://github.com/Mibew/advanced-button-plugin.git
synced 2025-04-12 04:50:10 +03:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
1bd23cf2c0 | |||
9a4dd4e8f5 | |||
d0f5b645bf | |||
bbeda61ab3 | |||
52c54dd5a5 | |||
6c89719f8b | |||
c29c7eeb5b | |||
16da0abed8 | |||
cda4d7041d | |||
3dc6be5a3f | |||
bcca037801 | |||
88f6c8285c | |||
44db483a25 | |||
b83f32cd3f | |||
b716005893 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
# Do not index node.js modules that are used for building
|
# Do not index node.js modules that are used for building
|
||||||
node_modules
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
# Do not index releases
|
# Do not index releases
|
||||||
release
|
release
|
||||||
|
47
Plugin.php
47
Plugin.php
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* Copyright 2018 the original author or authors.
|
* Copyright 2018, 2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -18,10 +18,7 @@
|
|||||||
namespace Mibew\Mibew\Plugin\AdvancedButton;
|
namespace Mibew\Mibew\Plugin\AdvancedButton;
|
||||||
|
|
||||||
use Mibew\Asset\Generator\UrlGeneratorInterface as AssetUrlGeneratorInterface;
|
use Mibew\Asset\Generator\UrlGeneratorInterface as AssetUrlGeneratorInterface;
|
||||||
use Mibew\Database;
|
|
||||||
use Mibew\EventDispatcher\EventDispatcher;
|
use Mibew\EventDispatcher\EventDispatcher;
|
||||||
use Mibew\EventDispatcher\Events;
|
|
||||||
use Mibew\Thread;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an ability to automatically refresh the button and set its
|
* Provides an ability to automatically refresh the button and set its
|
||||||
@ -31,6 +28,43 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi
|
|||||||
{
|
{
|
||||||
protected $initialized = true;
|
protected $initialized = true;
|
||||||
|
|
||||||
|
// Default operational mode is visibility cloaking
|
||||||
|
protected $mode = 'visibility';
|
||||||
|
|
||||||
|
// Default submode for display cloaking mode
|
||||||
|
protected $submode = 'inline-block';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param array $config List of the plugin config.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct($config)
|
||||||
|
{
|
||||||
|
// Set operational mode
|
||||||
|
if (isset($config['mode'])) {
|
||||||
|
switch($config['mode']) {
|
||||||
|
case 'display':
|
||||||
|
$this->mode = 'display';
|
||||||
|
if (isset($config['submode'])) {
|
||||||
|
switch($config['submode']) {
|
||||||
|
case 'block':
|
||||||
|
$this->submode = 'block';
|
||||||
|
break;
|
||||||
|
case 'inline':
|
||||||
|
$this->submode = 'inline';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'none':
|
||||||
|
$this->mode = 'none';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines necessary event listener.
|
* Defines necessary event listener.
|
||||||
*/
|
*/
|
||||||
@ -47,7 +81,7 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi
|
|||||||
*/
|
*/
|
||||||
public static function getVersion()
|
public static function getVersion()
|
||||||
{
|
{
|
||||||
return '0.0.1';
|
return '0.1.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,8 +92,9 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi
|
|||||||
public function refreshButton(&$args)
|
public function refreshButton(&$args)
|
||||||
{
|
{
|
||||||
$g = $args['asset_url_generator'];
|
$g = $args['asset_url_generator'];
|
||||||
$args['response']['load']['refresh'] = $g->generate($this->getFilesPath() . '/js/refresh.js', AssetUrlGeneratorInterface::ABSOLUTE_URL);
|
$args['response']['load']['refresh'] = $g->generate(str_replace(DIRECTORY_SEPARATOR, '/', $this->getFilesPath()) . '/js/refresh.js', AssetUrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
$args['response']['handlers'][] = 'refreshButton';
|
$args['response']['handlers'][] = 'refreshButton';
|
||||||
$args['response']['dependencies']['refreshButton'] = array('refresh');
|
$args['response']['dependencies']['refreshButton'] = array('refresh');
|
||||||
|
$args['response']['data']['refreshButton'] = array('mode' => $this->mode, 'submode' => $this->submode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
README.md
38
README.md
@ -1,22 +1,52 @@
|
|||||||
# Mibew Advanced Button plugin
|
# Mibew Advanced Button plugin
|
||||||
|
|
||||||
It make the button refresents actual operator's state and automatically hides it if the chat was started.
|
It make the button represents actual operator's state and automatically hides it if the chat was started.
|
||||||
|
|
||||||
|
Additionaly the plugin sets the class `mibew_visible` or `mibew_hidden` for the button depending on its alleged visibility. It can be useful for implementing some custom effects with cloaking mode (see below) set to `none`.
|
||||||
|
|
||||||
The plugin needs the feature "Tracking and inviting" to be enabled. Otherwise it will just not work.
|
The plugin needs the feature "Tracking and inviting" to be enabled. Otherwise it will just not work.
|
||||||
|
|
||||||
|
NB.: If one enabled the feature "Tracking and inviting" for the first time, the button should be regenerated.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Get the archive with the plugin sources. You can download it from the [official site](https://mibew.org/plugins#mibew-advanced-button) or build the plugin from sources.
|
1. Get the archive with the plugin sources. You can download it from the [official site](https://mibew.org/plugins#mibew-advanced-button) or build the plugin from sources.
|
||||||
|
|
||||||
2. Untar/unzip the plugin's archive.
|
2. Untar/unzip the plugin's archive.
|
||||||
|
|
||||||
3. Put files of the plugins to the `<Mibew root>/plugins` folder.
|
3. Put files of the plugins to the `<Mibew root>/plugins` folder.
|
||||||
|
|
||||||
4. Navigate to "`<Mibew Base URL>`/operator/plugin" page and enable the plugin.
|
4. (optional) Add plugins configs to "plugins" structure in
|
||||||
|
"`<Mibew root>`/configs/config.yml". If the "plugins" stucture looks like
|
||||||
|
`plugins: []` it will become:
|
||||||
|
```yaml
|
||||||
|
plugins:
|
||||||
|
"Mibew:AdvancedButton": # Plugin's configurations are described below
|
||||||
|
mode: display
|
||||||
|
submode: block
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Navigate to "`<Mibew Base URL>`/operator/plugin" page and enable the plugin.
|
||||||
|
|
||||||
## Plugin's configurations
|
## Plugin's configurations
|
||||||
|
|
||||||
The plugin has no configuration.
|
The plugin can be configured with values in "`<Mibew root>`/configs/config.yml" file.
|
||||||
|
|
||||||
|
### config.mode
|
||||||
|
|
||||||
|
Type: `String`
|
||||||
|
|
||||||
|
Default: `visibility`
|
||||||
|
|
||||||
|
Specify a mode to cloak the button after the start of the chat. Possible values: `visibility` (cloak using `visibility` CSS property), `display` (cloak using `display` CSS property), `none` (do nothing).
|
||||||
|
|
||||||
|
### config.submode
|
||||||
|
|
||||||
|
Type: `String`
|
||||||
|
|
||||||
|
Default: `inline-block`
|
||||||
|
|
||||||
|
Specify a value of the `display` CSS property for the visible button if mode was set to `display`.
|
||||||
|
|
||||||
## Build from sources
|
## Build from sources
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ var eventStream = require('event-stream'),
|
|||||||
gzip = require('gulp-gzip'),
|
gzip = require('gulp-gzip'),
|
||||||
rename = require('gulp-rename');
|
rename = require('gulp-rename');
|
||||||
|
|
||||||
gulp.task('prepare-release', [], function() {
|
gulp.task('prepare-release', function() {
|
||||||
var version = require('./package.json').version;
|
var version = require('./package.json').version;
|
||||||
|
|
||||||
return eventStream.merge(
|
return eventStream.merge(
|
||||||
@ -21,9 +21,7 @@ gulp.task('prepare-release', [], function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Builds and packs plugins sources
|
// Builds and packs plugins sources
|
||||||
gulp.task('default', ['prepare-release'], function() {
|
gulp.task('default', gulp.series('prepare-release'));
|
||||||
// The "default" task is just an alias for "prepare-release" task.
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns files stream with the plugin sources.
|
* Returns files stream with the plugin sources.
|
||||||
|
@ -1,9 +1,45 @@
|
|||||||
|
/*!
|
||||||
|
* This file is a part of Mibew Advanced Button Plugin
|
||||||
|
*
|
||||||
|
* Copyright 2014, 2018, 2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
(function(Mibew) {
|
(function(Mibew) {
|
||||||
Mibew.APIFunctions.refreshButton = function(data) {
|
Mibew.APIFunctions.refreshButton = function(data) {
|
||||||
// Refresh the button image
|
|
||||||
var img = document.getElementById("mibew-agent-button").getElementsByTagName("img")[0];
|
var button_object;
|
||||||
var originalSrc = img.src.replace(/&dummy=\d+/, '');
|
|
||||||
img.src = originalSrc + "&dummy=" + (new Date()).getTime();
|
var button = document.getElementById("mibew-agent-button");
|
||||||
|
if (!button) {
|
||||||
|
// The button is operator code field
|
||||||
|
button_object = document.getElementById("mibew-operator-code-field");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
button_object = button.getElementsByTagName("img")[0];
|
||||||
|
if (!button_object) {
|
||||||
|
// The button is text link
|
||||||
|
button_object = button;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// The button is image, refresh it
|
||||||
|
var originalSrc = button_object.src.replace(/&dummy=\d+/, '');
|
||||||
|
button_object.src = originalSrc + "&dummy=" + (new Date()).getTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unable to find button of any type - nothing to do
|
||||||
|
if (!button_object) { return; }
|
||||||
|
|
||||||
// Hide the button if all popups are open or make it visible otherwise
|
// Hide the button if all popups are open or make it visible otherwise
|
||||||
var visible = false;
|
var visible = false;
|
||||||
@ -11,6 +47,24 @@
|
|||||||
var popup = Mibew.Objects.ChatPopups[key];
|
var popup = Mibew.Objects.ChatPopups[key];
|
||||||
visible = visible || !popup.isOpened;
|
visible = visible || !popup.isOpened;
|
||||||
}
|
}
|
||||||
img.style.visibility = visible ? 'visible' : 'hidden';
|
|
||||||
|
// Check whether we actually need to hide the button
|
||||||
|
if (data.refreshButton.mode != 'none') {
|
||||||
|
if (data.refreshButton.mode == 'visibility') {
|
||||||
|
button_object.style.visibility = visible ? 'visible' : 'hidden';
|
||||||
|
}
|
||||||
|
else if (data.refreshButton.mode == 'display') {
|
||||||
|
button_object.style.display = visible ? data.refreshButton.submode : 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set appropriate class for the button depending on its alleged visibility
|
||||||
|
button_object.className = button_object.className.replace(/ mibew_(visible|hidden)/, '');
|
||||||
|
if (visible) {
|
||||||
|
button_object.className = button_object.className.concat(' mibew_visible');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
button_object.className = button_object.className.concat(' mibew_hidden');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})(Mibew);
|
})(Mibew);
|
||||||
|
18
package.json
18
package.json
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": ">3.8.10",
|
"gulp": "~4.0.0",
|
||||||
"event-stream": ">3.1.7",
|
"event-stream": "~3.3.4",
|
||||||
"gulp-zip": ">2.0.2",
|
"gulp-zip": "~2.0.2",
|
||||||
"gulp-tar": ">1.3.1",
|
"gulp-tar": "~3.1.0",
|
||||||
"gulp-gzip": ">0.0.8",
|
"gulp-gzip": "~0.0.8",
|
||||||
"gulp-chmod": ">1.2.0",
|
"gulp-chmod": "~3.0.0",
|
||||||
"gulp-rename": ">1.2.0"
|
"gulp-rename": "~1.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user