<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">$(document).ready(function(){
	bindGlobalFacebookEvents ();
	bindFacebookPhotoUploadEvents ();
});

/**
 * 	Namespace for facebook actions
 */
var LLFacebook = function () {
	var sdkDoneLoading = false;
	return {		
		//	when set, currentStatus has fields (connected, id, accessToken, and signedRequest)
		//	and it is what you get in your onLogin and checkLoginStatus callbacks (in onLogin, connected will be true)
		currentStatus : null,
		
		//	mechanism for scheduling code to run as soon as the FB SDK is loaded
		onSDKLoaded : [],
		onLoad : function (callback)
		{
			LLFacebook.onSDKLoaded.push(callback);
		},
		sdkLoaded : function ()
		{
			sdkDoneLoading = true;
			$.each (LLFacebook.onSDKLoaded, function (index, callback) {
				callback ();
			});
		},
		isActive: function () {
			return sdkDoneLoading;
		},
		
		login : function (loginCallback, scope) {
			var doLogin = function (callback, scope) {
				FB.login(function(response) {
					var loggedIn = false;
					if (response.authResponse) 
					{
						var granted = {};
						$.each (response.authResponse.grantedScopes.split (','), function (index, perm) {
							granted[perm] = true;
						});
						if (LLFacebook.scopeCovered (granted, scope)) {
							loggedIn = true;
						}
					}
					if (loggedIn) {
						LLFacebook.currentStatus = LLFacebook.parseCurrentStatus (true, response.authResponse);
						callback (LLFacebook.currentStatus);
					} else {
						LLFacebook.onLoginCancel (response);
					}
				},
				{ scope: scope, return_scopes: true });		
			};

			if (!scope) {
				scope = LLFacebook.defaultScope;
			}
			LLFacebook.checkLoginStatus (function (status) {
				if (!loginCallback) {
					loginCallback = LLFacebook.onLogin;
				}
				
				if (status.connected)
				{
					LLFacebook.checkScope (scope, function (scopeCovered) {
						if (scopeCovered) {
							loginCallback (status);
						} else {
							doLogin (loginCallback, scope);
						}
					});
				} else {
					doLogin (loginCallback, scope);
				}
			});
		},
		
		getUserInfo : function (callback)
		{
			// fields are id, first_name, last_name, gender, email, username 
			FB.api('/me', function (response) { callback (response); });
		},

		getInfoForImagePost : function (callback)
		{
			FB.api('/me?fields=albums,accounts,first_name,last_name', function (response) { callback (response); });
		},

		getPageAlbums : function (pageID, callback)
		{
			FB.api('/' + pageID + '/albums', function (response) { callback (response); });
		},
		
		checkLoginStatus : function (callback, forceReload)
		{
			if (LLFacebook.currentStatus &amp;&amp; LLFacebook.currentStatus.connected &amp;&amp; !forceReload)
			{
				//	if we're already connected, not much is changing, so we cache the info
				callback (LLFacebook.currentStatus);
			}
			else
			{
				FB.getLoginStatus(
					function(response) {
						LLFacebook.currentStatus = LLFacebook.parseCurrentStatus (response.status == 'connected', response.authResponse);
						callback (LLFacebook.currentStatus);
					}
				);
			}
		},
		
		//	read the info supplied by Facebook and store the connection status and info here
		parseCurrentStatus : function (connected, authResponse)
		{
			var status = {
				connected : false,
				id : null,
				accessToken : null,
				signedRequest : null
			};
			if (connected) {
				status.connected = true;
				status.id = authResponse.userID;
				status.accessToken = authResponse.accessToken;
				status.signedRequest = authResponse.signedRequest;
			}
			return status;
		},
		
		//	override these to do something with the response
		onLogin : function (response) { return; },
		onLoginCancel : function (response) { return; },
		
		linkFacebookIDToCurrentAccount : function (accessToken, source, success, failure) {
			var info = {
				action : 'LinkFacebookAccount',
				AccessToken: accessToken,
				Source: source
			};
			setTokenValue (info);
			$.post(LLFacebook.facebookActionUrl, info, function(response,status)
			{
				if(status == "success" &amp;&amp; response == "SUCCESS")
				{
					success ();
				}
				else
				{
					failure ();
				}
			},"text");
		},

		unlinkCurrentAccount : function (success, failure) {
			var info = {
				action : 'UnlinkFacebookAccount'
			};
			setTokenValue (info);
			$.post(LLFacebook.facebookActionUrl, info, function(response,status)
			{
				if(status == "success" &amp;&amp; response == "SUCCESS")
				{
					success ();
				}
				else
				{
					failure ();
				}
			},"text");
		},
		
		loginViaFacebook : function (currentStatus, callback, createAccount, autoLogin, source) {
			LLFacebook.getUserInfo (function (user) {
				var info = {
					action : 'LoginViaFacebook',
					AccessToken: currentStatus.accessToken,
					CreateAccount : createAccount ? 1 : 0,
					LinkedOnly: autoLogin ? 1 : 0,
					Source: source 
				};
				setTokenValue (info);
				$.post(LLFacebook.facebookActionUrl, info, function(response,status)
				{
					if(status == "success")
					{
						/*
						*	response looks like { 
						*		Status: "Pending",
						*		CandidateAccounts: [ { (acct info) }, ... ],
						*		LoginRedirect: '/url' }
						*	Status can be SUCCESS, ERROR, Pending, or Not Found
						*	Pending and Not Found are handled below, while the others are handled in the callback
						*/

						try {
							response = $.parseJSON (response);
						} catch ($e) {
							response = { Status: 'ERROR' };
						}

						if (response.Status == 'Not Found' &amp;&amp; !autoLogin) {
							LLFacebook.setFeedbackMessage ('noAccount');
							resetSpinnerAndButtons ();
						} else if (response.Status == 'Staff') {
							LLFacebook.setFeedbackMessage ('staffAccount');
							resetSpinnerAndButtons ();
						} else if (response.Status == 'Pending') {
							LLFacebook.showUserChooserPopup (user, currentStatus.accessToken, response.CandidateAccounts, response.LoginRedirect, callback);
						} else {
							callback (response);
						}
					}
				},"text");
			});
		},

		showUserChooserPopup: function (fbUser, access_token, matchingAccounts, loginRedirect, callback) {
			var popup = $("#fb-user-chooser");
			var hasStaff = false;
			popup.data ('login_info', {
				response: { CandidateAccounts: [], LoginRedirect: loginRedirect },
				callback: callback,
				access_token: access_token
			});
			popup.find (".fb-email-address").text (fbUser.email);
			var tableBody = popup.find ("tbody").html ('');
			$.each (matchingAccounts, function (index, account) {
				var row = $('&lt;tr/&gt;', { 'data-userid': account.UserID });
				$('&lt;td/&gt;', { text: account.FirstName + ' ' + account.LastName}).appendTo (row);
				$('&lt;td/&gt;', { text: account.Username }).appendTo (row);
				$('&lt;td/&gt;', { text: account.LastActiveFormatted }).appendTo (row);
				var actionCell = $('&lt;td/&gt;');
				if (account.Staff == "1") {
					hasStaff = true;
					$('&lt;span/&gt;', { text: 'N/A*', 'class': 'staff' }).appendTo (actionCell);
				} else {
					$('&lt;a/&gt;', { href: '#', text: 'Log In', 'class': 'selectUser btn-sm btn-org' }).appendTo (actionCell);
				}
				actionCell.appendTo (row);
				row.appendTo (tableBody);
			});
			if (hasStaff) {
				popup.find ('.staffAccountNotice').show ();
			} else {
				popup.find ('.staffAccountNotice').hide ();
			}
			LLUtil.stripe ('#fb-user-chooser tbody tr');
			$("#fb-open-user-chooser").trigger ('click');

			if (!ll_fancyboxInitDone) {
				console.log ('Fancybox is not set up! Call bindFancyboxEvents() in the script on this page.');
			}
		},

		finishLoginWithChosenUser: function (userID) {
			var popup = $("#fb-user-chooser");
			var login_info = popup.data ('login_info');
			
			LLUtil.replaceButtonWithSpinner (popup.find ('.selectUser'), 20);

			var info = {
				action: 'LinkSelectedUserAcccount',
				AccessToken: login_info.access_token,
				UserID: userID
			};
			setTokenValue (info);

			$.post(LLFacebook.facebookActionUrl, info, function(response, status) {
				login_info.response.Status = response;
				login_info.callback (login_info.response);
			},"text");
		},
		
		uploadPhoto : function (imageID, albumID, title, page_id, access_token, success, failure) {
			var info = {
				action : 'PostPhoto',
				ImageID : imageID,
				AlbumID: albumID,
				Title : title,
				PageID: page_id,
				access_token : access_token
			};
			setTokenValue (info);
			
			$.post(LLFacebook.facebookActionUrl, info, function(response,status)
			{
				if(status == "success" &amp;&amp; response == "SUCCESS")
				{
					success ();
				}
				else
				{
					failure ();
				}
			},"text");
		},

		getPermissions: function (callback)
		{
			FB.api('/me/permissions', function (response) { 
				var perms = {};
				if (response &amp;&amp; response.data) {
					$.each (response.data, function (index, perm) {
						if (perm.status == "granted") {
							perms[perm.permission] = true;
						}
					});
				}
				callback (perms);
			});
		},

		checkScope: function (scope, callback) {
			LLFacebook.getPermissions (function (permissions) {
				callback (LLFacebook.scopeCovered (permissions, scope));
			});
		},

		scopeCovered: function (aGranted, sRequested) {
			var scopeCovered = true;
			$.each (sRequested.split (','), function (index, perm) {
				if (!aGranted[$.trim (perm)]) {
					scopeCovered = false;
					return false;
				}
			});
			return scopeCovered;
		},
		
		getMultipleProfiles : function (aIDs, callback)
		{
			var batch = [];
			$.each (aIDs, function (key, id) {
				batch.push ({
					method: 'GET',
					relative_url: id + "?fields=id,first_name,last_name,name,picture,gender"
				});
			});
			LLFacebook.checkLoginStatus (function (currentStatus) {
				if (currentStatus.accessToken) {
					var params = {
						batch: batch,
						access_token: currentStatus.accessToken
					};
					FB.api ('/', 'post', { batch: batch }, function (responses) { 
						var users = [];
						$.each (responses, function (key, response) {
							var userInfo = $.parseJSON (response.body);
							if (response.code == 200) {
								var user = $.extend ({}, userInfo);
								user.pic = userInfo.picture.data.url;
								user.pic_is_default = userInfo.picture.data.is_silhouette;
								delete user.picture;
								users.push(user);
							}
						});
						callback (users); 
					});
				} else {
					callback ([]);
				}
			});
		},

		requestDialog: function (teamID, message, callback) {
			FB.ui({
					method: 'apprequests',
					message: message
				}, function (response) {
					if (response &amp;&amp; response.request &amp;&amp; response.to.length &gt; 0) {
						var requestID = response.request;
						var facebookIDs = response.to;
						LLFacebook.getMultipleProfiles (facebookIDs, function (fbUsers) {
							var toInvite = [];
							$.each (fbUsers, function (key, fbUser) {
								toInvite.push ({
									FacebookID: fbUser.id,
									FirstName: fbUser.first_name,
									LastName: fbUser.last_name,
									Gender: fbUser.gender,
									ProfileImage: fbUser.pic,
									pic_is_default: fbUser.pic_is_default,
									FacebookRequestID: requestID
								});
							});

							var info = {
								action: 'RecordInvites',
								FacebookRequestID: requestID,
								Invites: JSON.stringify (toInvite),
								TeamID: teamID
							};
							setTokenValue (info);

							$.post(LLFacebook.facebookActionUrl, info, function(response,status)
							{
								if(status == "success" &amp;&amp; response != "ERROR") {
									var playersInvited = $.parseJSON (response);
									callback (playersInvited);
								} else {
									LLFacebook.setFeedbackMessage ('inviteError');
								}
							},"text");
						});
					}
					else if (response.error_message){
						LLFacebook.reportError(response.error_message);
					}
				}
			);
		},

		deleteRequests : function (teamID, participantIDs, callback) {
			var info = {
				action: 'DeleteInvites',
				ParticipantIDs: participantIDs.join (','),
				TeamID: teamID
			};
			setTokenValue (info);

			$.post(LLFacebook.facebookActionUrl, info, function(response,status)
			{
				if (callback) {
					callback (response);
				}
			},"text");
		},
		
		sendRequests : function (message, friendIDs, callback)
		{
			if (friendIDs instanceof Array) {
				friendIDs = friendIDs.join(',')
			}
			FB.ui(
				{
					method: 'apprequests',
					message: message,
					to: friendIDs
				}, 
				function (response) { callback (response); }
			);
		},
		
		addPageTab : function (callback)
		{
			FB.ui (
				{
					method: 'pagetab'
				},
				function (response) { callback (response); }
			);
		},

		setFeedbackMessage : function (messageType) {
			var msgBox = $("#fb-feedback");
			msgBox.find ('.feedback').addClass ('hidden').filter ('.' + messageType).removeClass ('hidden');
			msgBox.removeClass ('').addClass (messageType).hide ();
			msgBox.prependTo ($('body')).slideDown (400);
		},
		
		//	@BUGBUG: We use the private _apiKey property to get our app id... this may break!
		removePageTab : function (pageID, callback)
		{
			FB.api('/' + pageID + '?fields=access_token', function (response) { 
				FB.api (
					'/' + pageID + '/tabs/app_' + FB._apiKey + '?access_token=' + response.access_token,
					'delete',
					function (responseTwo) { 
						callback (responseTwo); 
					}
				);
			});
		},
		
		updatePrimaryFacebookPage : function (llFacebookPageID, success, failure)
		{
			var info = {
				action : 'UpdatePrimaryFacebookPage',
				FacebookPageID : llFacebookPageID
			};
			setTokenValue (info);
			
			$.post(LLFacebook.facebookActionUrl, info, function(response,status)
			{
				if(status == "success" &amp;&amp; response == "SUCCESS")
				{
					success ();
				}
				else
				{
					failure ();
				}
			},"text");
		},

		reportError: function (errorMessage) {
			var info = {
				action : 'ReportError',
				Message : errorMessage
			};
			setTokenValue (info);
			$.post(LLFacebook.facebookActionUrl, info, function (response, status){
				console.log ('Facebook Error: ' + errorMessage);
			},"text");
		},

		facebookActionUrl : '/async/facebook',
		defaultScope : 'public_profile,email'
	};
}();

function bindFacebookPhotoUploadEvents () {
	if ($("#postImageToFacebook").length &gt; 0) {

		function updateAlbumList (albums) {
			var albumSelector = $("#facebookAlbumSelector").html ('');
			$.each (albums, function (key, album) {
				$('&lt;option/&gt;', { value: album.id, text: album.name }).appendTo (albumSelector);
			});
		}

		function doUpload () {
			var id = $("#facebookAlbumSelector").val ();
			var account_id = $("#facebookAccountSelector").val ();
			if (!id) {
				id = account_id;
			}
			var fbInfo = $("#postImageToFacebookContainer").data ('FBInfo');
			var page_id = (account_id == fbInfo.FacebookUserID) ? '' : account_id;
			var image_id = $("#postImageToFacebook").attr ('data-imageid');
			var title = $("#postImageToFacebook").attr ('data-title');

			$("#postImageToFacebookContainer").removeClass ("active error").addClass ("loading");
			LLFacebook.uploadPhoto (
				image_id,
				id,
				title,
				page_id,
				fbInfo.AccessToken,
				function () {
					$("#postImageToFacebookContainer").removeClass ("loading").addClass ("success");
					setTimeout (function () { $.fancybox.close (); }, 1000);
				}, 
				function () {
					$("#postImageToFacebookContainer").removeClass ("loading").addClass ("error");
				}
			);
		}

		$("#postImageToFacebook").on ('click', function () {
			if (!ll_fancyboxInitDone) {
				console.log ('Fancybox is not set up! Call bindFancyboxEvents() in the script on this page.');
			}
			$("#postToFacebookPreview").attr ('src', $(this).attr ('href'));
			$("#postImageToFacebookContainer").removeClass ("error success loading").addClass ("active");
			$("#openPostToFacebook").trigger ('click');

			if ($("#facebookAlbumSelector option").length &gt; 0) {
				return false; 	//	the controls are already initialized
			}

			LLFacebook.login (function (status) {
				if (!status.connected) {
					$.fancybox.close ();
					return;
				}
				LLFacebook.getInfoForImagePost (function (me) {
					var user_name = me.first_name + ' ' + me.last_name; 
					var user_id = me.id;
					var my_albums = me.albums ? me.albums.data : [];
					var my_pages = me.accounts ? me.accounts.data : [];
					var acctSelector = $("#facebookAccountSelector").html ('');
					$('&lt;option/&gt;', { value: user_id, text: user_name }).appendTo (acctSelector);
					$.each (my_pages, function (key, page) {
						$('&lt;option/&gt;', { value: page.id, text: page.name }).appendTo (acctSelector);
					});
					acctSelector.val (user_id);
					acctSelector.unbind ('change').on ('change', function () {
						var account_id = $(this).val ();
						LLFacebook.getPageAlbums (account_id, function (albums) {
							updateAlbumList (albums.data);
						});
					});

					if (my_pages.length &gt; 0) {
						acctSelector.parents ('p.inputRow').show ();
					} else {
						acctSelector.parents ('p.inputRow').hide ();
					}
					updateAlbumList (my_albums);

					//	Bind other events
					$("#postImageToFacebookSubmit").unbind ('click').on ('click', function () {
						doUpload ();
						return false;
					});
					$("#postImageToFacebookContainer").unbind ('click').on ('click', '.tryAgain', function () {
						$("#postImageToFacebookContainer").removeClass ("error").addClass ("active");
					}).on ('click', '.cancel', function () {
						$.fancybox.close ();
					});

					//	save some data for later use
					$("#postImageToFacebookContainer").data ('FBInfo', {
						FacebookUserID: user_id,
						AccessToken: status.accessToken
					});
				});
			}, 'email,user_photos,manage_pages,publish_actions');
			return false;
		});
	}
}

function resetSpinnerAndButtons () {
	$(".facebookButton").show ();
	$(".loadingGraphic").hide ();
}

function bindGlobalFacebookEvents () {
	/**
	*	in page code, override LLFacebook.onLogin to control what happens when the login is finished
	*/
	$(".facebookLoginButton,.facebookSignupButton,.facebookConnectButton,.facebookLoginPlain").click (function () {
		if ($(this).hasClass ('disabled-for-admin')) {
			alert ('Sorry. As an admin user, you cannot connect to Facebook on behalf of the player.');
			return false;
		}
		LLUtil.replaceButtonWithSpinner ($(this), 30);
		LLFacebook.login ();
		return false;
	});

	//	default action when user cancels login (or refuses permissions)
	LLFacebook.onLoginCancel = function () {
		LLFacebook.setFeedbackMessage ('loginError');
		resetSpinnerAndButtons ();
	};

	$("#fb-feedback").on ("click", function () {
		$(this).slideUp ();
	});

	$("#fb-user-chooser").on ('click', '.cancel', function () {
		$.fancybox.close ();
		resetSpinnerAndButtons ();
		return false;
	}).on ('click', '.selectUser', function () {
		var userID = $(this).parents ('tr').attr ('data-userid');
		LLFacebook.finishLoginWithChosenUser (userID);
		return false;
	});

	$(".fb-account-unlink").on ("click", function () {
		LLUtil.replaceButtonWithSpinner ($(this));
		$("#facebookUnlinkContainer p").hide ();
		LLFacebook.unlinkCurrentAccount (function () {
			$("#facebookUnlinkContainer").hide ();
			LLFacebook.setFeedbackMessage ('unlink');
		}, function () {
			$("#facebookUnlinkContainer .loadingGraphic").hide ();
			$("#facebookUnlinkContainer .fb-account-unlink, #facebookUnlinkContainer p").show ();
			LLFacebook.setFeedbackMessage ('unlinkError');
		});
	});
	
	/**
	 * 	If the fb-root element (inserted by the SDK) has the checkLoginStatus (only exists on first try of the session),
	 * 	we check to see if the user is logged-in with an authorized, linked Facebook account. If so, we log them in!
	 */
	if ($("#fb-root").hasClass('checkLoginStatus'))
	{
		LLFacebook.onLoad (function () { LLFacebook.checkLoginStatus(
			function(status) {
				if (status.connected) {
					LLFacebook.loginViaFacebook (status, function (response) {
						if (response.Status == 'SUCCESS') {
							LLFacebook.setFeedbackMessage ('autoLogin');
						}
					}, false, true, 'Auto Login');
				}
			}
		)});
	}
}
</pre></body></html>