@@ -17,106 +17,106 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class UloginWidget extends Widget |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * @var array Layouts buttons |
|
| 22 | - * @see http://ulogin.ru/help.php#buttons |
|
| 23 | - */ |
|
| 24 | - public $buttons = []; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string HTML The class attribute |
|
| 28 | - * @see http://htmlbook.ru/html/attr/class |
|
| 29 | - */ |
|
| 30 | - public $classAttr = ''; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var array Js event handlers |
|
| 34 | - * @see https://ulogin.ru/help.php#listeners |
|
| 35 | - */ |
|
| 36 | - public $eventListeners = []; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array Ulogin options |
|
| 40 | - * @see https://ulogin.ru/help.php |
|
| 41 | - */ |
|
| 42 | - public $options = []; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var string Ulogin init buttons |
|
| 46 | - */ |
|
| 47 | - private $_initButtons; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string Ulogin init options |
|
| 51 | - */ |
|
| 52 | - private $_initOptions; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @inheritdoc |
|
| 56 | - */ |
|
| 57 | - public function init() |
|
| 58 | - { |
|
| 59 | - $initOptions = ''; |
|
| 60 | - foreach ($this->options as $option => $value) { |
|
| 61 | - if (is_array($value)) { |
|
| 62 | - $initOptions .= $option . '=' . implode(',', $value) . ';'; |
|
| 63 | - } else { |
|
| 64 | - $initOptions .= $option . '=' . $value . ';'; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $initButtons = []; |
|
| 69 | - foreach ($this->buttons as $button) { |
|
| 70 | - $data = "data-uloginbutton=\"{$button['provider']}\""; |
|
| 71 | - $initButtons[] = $button['layout']($data); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $this->_initOptions = $initOptions; |
|
| 75 | - $this->_initButtons = $initButtons; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - parent::init(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @inheritdoc |
|
| 83 | - */ |
|
| 84 | - public function run() |
|
| 85 | - { |
|
| 86 | - |
|
| 87 | - UloginAsset::register($this->getView()); |
|
| 88 | - |
|
| 89 | - // Register event listeners |
|
| 90 | - foreach ($this->eventListeners as $event => $listener) { |
|
| 91 | - $this->setStateListener($event, $listener); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $this->render('widget', [ |
|
| 95 | - 'class' => $this->classAttr, |
|
| 96 | - 'buttons' => $this->_initButtons, |
|
| 97 | - 'id' => $this->id, |
|
| 98 | - 'initOptions' => $this->_initOptions, |
|
| 99 | - ]); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Sets the event handler in the event ulogin |
|
| 104 | - * |
|
| 105 | - * @param string $event Js event name |
|
| 106 | - * @param string $listener Js event handler |
|
| 107 | - * @return $this |
|
| 108 | - * @see https://ulogin.ru/help.php#listeners |
|
| 109 | - */ |
|
| 110 | - public function setStateListener($event, $listener) |
|
| 111 | - { |
|
| 112 | - $js = sprintf( |
|
| 113 | - 'uLogin.setStateListener("%s", "%s", %s);', |
|
| 114 | - $this->id, |
|
| 115 | - $event, |
|
| 116 | - $listener |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - $this->getView()->registerJs($js); |
|
| 120 | - return $this; |
|
| 121 | - } |
|
| 20 | + /** |
|
| 21 | + * @var array Layouts buttons |
|
| 22 | + * @see http://ulogin.ru/help.php#buttons |
|
| 23 | + */ |
|
| 24 | + public $buttons = []; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string HTML The class attribute |
|
| 28 | + * @see http://htmlbook.ru/html/attr/class |
|
| 29 | + */ |
|
| 30 | + public $classAttr = ''; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var array Js event handlers |
|
| 34 | + * @see https://ulogin.ru/help.php#listeners |
|
| 35 | + */ |
|
| 36 | + public $eventListeners = []; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array Ulogin options |
|
| 40 | + * @see https://ulogin.ru/help.php |
|
| 41 | + */ |
|
| 42 | + public $options = []; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var string Ulogin init buttons |
|
| 46 | + */ |
|
| 47 | + private $_initButtons; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string Ulogin init options |
|
| 51 | + */ |
|
| 52 | + private $_initOptions; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @inheritdoc |
|
| 56 | + */ |
|
| 57 | + public function init() |
|
| 58 | + { |
|
| 59 | + $initOptions = ''; |
|
| 60 | + foreach ($this->options as $option => $value) { |
|
| 61 | + if (is_array($value)) { |
|
| 62 | + $initOptions .= $option . '=' . implode(',', $value) . ';'; |
|
| 63 | + } else { |
|
| 64 | + $initOptions .= $option . '=' . $value . ';'; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $initButtons = []; |
|
| 69 | + foreach ($this->buttons as $button) { |
|
| 70 | + $data = "data-uloginbutton=\"{$button['provider']}\""; |
|
| 71 | + $initButtons[] = $button['layout']($data); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $this->_initOptions = $initOptions; |
|
| 75 | + $this->_initButtons = $initButtons; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + parent::init(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @inheritdoc |
|
| 83 | + */ |
|
| 84 | + public function run() |
|
| 85 | + { |
|
| 86 | + |
|
| 87 | + UloginAsset::register($this->getView()); |
|
| 88 | + |
|
| 89 | + // Register event listeners |
|
| 90 | + foreach ($this->eventListeners as $event => $listener) { |
|
| 91 | + $this->setStateListener($event, $listener); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $this->render('widget', [ |
|
| 95 | + 'class' => $this->classAttr, |
|
| 96 | + 'buttons' => $this->_initButtons, |
|
| 97 | + 'id' => $this->id, |
|
| 98 | + 'initOptions' => $this->_initOptions, |
|
| 99 | + ]); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Sets the event handler in the event ulogin |
|
| 104 | + * |
|
| 105 | + * @param string $event Js event name |
|
| 106 | + * @param string $listener Js event handler |
|
| 107 | + * @return $this |
|
| 108 | + * @see https://ulogin.ru/help.php#listeners |
|
| 109 | + */ |
|
| 110 | + public function setStateListener($event, $listener) |
|
| 111 | + { |
|
| 112 | + $js = sprintf( |
|
| 113 | + 'uLogin.setStateListener("%s", "%s", %s);', |
|
| 114 | + $this->id, |
|
| 115 | + $event, |
|
| 116 | + $listener |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + $this->getView()->registerJs($js); |
|
| 120 | + return $this; |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | \ No newline at end of file |