authchoice.js 2.32 KB
Newer Older
1 2 3
/**
 * Yii auth choice widget.
 *
4
 * This is the JavaScript widget used by the yii\authclient\widgets\AuthChoice widget.
5 6 7 8 9 10 11
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 * @author Paul Klimov <klimov.paul@gmail.com>
 * @since 2.0
 */
12
jQuery(function($) {
13 14 15 16 17 18 19 20 21 22 23 24 25 26
    $.fn.authchoice = function(options) {
        options = $.extend({
            popup: {
                resizable: 'yes',
                scrollbars: 'no',
                toolbar: 'no',
                menubar: 'no',
                location: 'no',
                directories: 'no',
                status: 'yes',
                width: 450,
                height: 380
            }
        }, options);
27

28 29
        return this.each(function() {
            var $container = $(this);
30

31 32
            $container.find('a').on('click', function(e) {
                e.preventDefault();
33

dima committed
34
                var authChoicePopup = $container.data('authChoicePopup');
35

dima committed
36
                if (authChoicePopup) {
37 38
                    authChoicePopup.close();
                }
39

40
                var url = this.href;
41
                var popupOptions = $.extend({}, options.popup); // clone
42

43 44 45 46 47 48 49 50
                var localPopupWidth = this.getAttribute('data-popup-width');
                if (localPopupWidth) {
                    popupOptions.width = localPopupWidth;
                }
                var localPopupHeight = this.getAttribute('data-popup-height');
                if (localPopupWidth) {
                    popupOptions.height = localPopupHeight;
                }
51

dima committed
52 53
                popupOptions.left = (window.screen.width - popupOptions.width) / 2;
                popupOptions.top = (window.screen.height - popupOptions.height) / 2;
54

55 56
                var popupFeatureParts = [];
                for (var propName in popupOptions) {
Klimov Paul committed
57 58 59
                    if (popupOptions.hasOwnProperty(propName)) {
                        popupFeatureParts.push(propName + '=' + popupOptions[propName]);
                    }
60 61
                }
                var popupFeature = popupFeatureParts.join(',');
62

63 64
                authChoicePopup = window.open(url, 'yii_auth_choice', popupFeature);
                authChoicePopup.focus();
65

66 67 68 69
                $container.data('authChoicePopup', authChoicePopup);
            });
        });
    };
70
});