diff --git a/Plugin.php b/Plugin.php index c1f2333..c4763e1 100644 --- a/Plugin.php +++ b/Plugin.php @@ -31,6 +31,43 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi { 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. */ @@ -47,7 +84,7 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi */ public static function getVersion() { - return '0.0.1'; + return '0.0.2'; } /** @@ -61,5 +98,6 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi $args['response']['load']['refresh'] = $g->generate($this->getFilesPath() . '/js/refresh.js', AssetUrlGeneratorInterface::ABSOLUTE_URL); $args['response']['handlers'][] = 'refreshButton'; $args['response']['dependencies']['refreshButton'] = array('refresh'); + $args['response']['data']['refreshButton'] = array('mode' => $this->mode, 'submode' => $this->submode); } } diff --git a/README.md b/README.md index 4c4b44f..fb9caf8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ It make the button represents actual operator's state and automatically hides it 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 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. @@ -12,11 +14,37 @@ The plugin needs the feature "Tracking and inviting" to be enabled. Otherwise it 3. Put files of the plugins to the `/plugins` folder. -4. Navigate to "``/operator/plugin" page and enable the plugin. +4. (optional) Add plugins configs to "plugins" structure in +"``/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 "``/operator/plugin" page and enable the plugin. ## Plugin's configurations -The plugin has no configuration. +The plugin can be configured with values in "``/configs/config.yml" file. + +### config.mode + +Type: `String` + +Default: `visibility` + +Specify a mode to hide the button after the start of the chat. Possible values: `visibility` (hide using `visibility` CSS property), `display` (hide 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 diff --git a/js/refresh.js b/js/refresh.js index e9be43d..ce52ebf 100644 --- a/js/refresh.js +++ b/js/refresh.js @@ -5,12 +5,20 @@ var originalSrc = img.src.replace(/&dummy=\d+/, ''); img.src = originalSrc + "&dummy=" + (new Date()).getTime(); - // Hide the button if all popups are open or make it visible otherwise - var visible = false; - for(var key in Mibew.Objects.ChatPopups) { - var popup = Mibew.Objects.ChatPopups[key]; - visible = visible || !popup.isOpened; + // Check whether we need to hide the button + if (data.refreshButton.mode != 'none') { + // Hide the button if all popups are open or make it visible otherwise + var visible = false; + for(var key in Mibew.Objects.ChatPopups) { + var popup = Mibew.Objects.ChatPopups[key]; + visible = visible || !popup.isOpened; + } + if (data.refreshButton.mode == 'visibility') { + img.style.visibility = visible ? 'visible' : 'hidden'; + } + else if (data.refreshButton.mode == 'display') { + img.style.display = visible ? data.refreshButton.submode : 'none'; + } } - img.style.visibility = visible ? 'visible' : 'hidden'; } })(Mibew); diff --git a/package.json b/package.json index bfb68f8..3ac1c33 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.0.1", + "version": "0.0.2", "devDependencies": { "gulp": ">3.8.10", "event-stream": ">3.1.7",