diff --git a/README.md b/README.md index 6d0fbe1..90105d0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![latest_tag](https://badgen.net/github/tag/Matej-ch/yii2-page-guide) -![https://github.com/Matej-ch/yii2-page-guide/wiki](https://badgen.net/badge/icon/wiki?icon=wiki&label) +![wiki](https://badgen.net/badge/icon/wiki?icon=wiki&label) Page guide extension ==================== @@ -67,6 +67,16 @@ More options here [intro.js](https://introjs.com/docs/examples/customizing/html- ```php ['showProgress' => true] ]) ?> +``` +### 5. Optional + +Widget now also supports intro.js callbacks + +Available callbacks are `oncomplete` `onexit` `onbeforeexit` `onchange` `onbeforechange` `onafterchange` + +```php + ['onchange' => ] ]) ?> + ``` Usage diff --git a/src/web/js/assist.js b/src/web/js/assist.js index b5dd5b6..d844c3a 100644 --- a/src/web/js/assist.js +++ b/src/web/js/assist.js @@ -58,6 +58,11 @@ document.addEventListener('DOMContentLoaded',() => { intro.setOption("nextLabel",window.guideLabels.nextLabel || 'Next' ); intro.setOption("skipLabel",window.guideLabels.skipLabel || 'Skip' ); intro.setOption("doneLabel",window.guideLabels.doneLabel || 'Done' ); + + if(window.guideCallbacks) { + console.log(window.guideCallbacks) + } + intro.start(); } diff --git a/src/web/js/assist.min.js b/src/web/js/assist.min.js index 8e7126b..5c8b452 100644 --- a/src/web/js/assist.min.js +++ b/src/web/js/assist.min.js @@ -1 +1 @@ -"use strict";function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);ca.length)&&(b=a.length);for(var c=0,d=Array(b);cintroOptions,['steps' => Json::decode($guide->rules)])); - $view->registerJs("window.guideRules=$options;window.guideLabels=$labels"); + $jsString = "window.guideRules=$options;window.guideLabels=$labels;"; + if(!empty($this->introCallbacks)) { + $callbacks = $this->filterCallbacks(); + $jsString = "window.guideCallbacks=$callbacks"; + } + + $view->registerJs($jsString); } if(!empty($this->selectors)) { @@ -79,4 +105,21 @@ public function registerTranslations() ]; } } + + private function filterCallbacks(): string + { + return Json::encode(array_intersect_key($this->introCallbacks,array_flip($this->allowedCallbacks()))); + } + + private function allowedCallbacks(): array + { + return [ + 'oncomplete', + 'onexit', + 'onbeforeexit', + 'onchange', + 'onbeforechange', + 'onafterchange', + ]; + } } \ No newline at end of file