Blame view

common/components/nodge/eauth/src/assets/js/eauth.js 1.25 KB
b0f143c3   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  /*
   * Yii EAuth extension.
   * @author Maxim Zemskov
   * @link http://github.com/Nodge/yii2-eauth/
   * @license http://www.opensource.org/licenses/bsd-license.php
   */
  (function ($) {
  	var popup,
  		defaults = {
  			popup: {
  				width: 450,
  				height: 380
  			}
  		};
  
  	function openPopup(options) {
  		if (popup != null)
  			popup.close();
  
  		var redirect_uri,
  			url = redirect_uri = options.url;
  
  		url += url.indexOf('?') >= 0 ? '&' : '?';
  		if (url.indexOf('redirect_uri=') === -1)
  			url += 'redirect_uri=' + encodeURIComponent(redirect_uri) + '&';
  		url += 'js=';
  
  		var centerWidth = (window.screen.width - options.popup.width) / 2,
  			centerHeight = (window.screen.height - options.popup.height) / 2;
  
  		popup = window.open(url, "yii_eauth_popup", "width=" + options.popup.width + ",height=" + options.popup.height + ",left=" + centerWidth + ",top=" + centerHeight + ",resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes");
  		popup.focus();
  	}
  
  	$.fn.eauth = function (services) {
  		$(this).on('click', '[data-eauth-service]', function (e) {
  			e.preventDefault();
  
  			var service = $(this).data('eauthService'),
  				options = $.extend({
  					url: this.href
  				}, defaults, services[service]);
  
  			openPopup(options);
  		});
  	};
  })(jQuery);