PageSourceSearch

https://www.elephanttrust.org/wp-content/plugins/login-with-ajax/templates/login-with-ajax.legacy.js?ver=4.5.1

js elephanttrust.org collected 2026-10-02 05:05:27 UTC 10,230 bytes, 305 lines download raw bytes

1/* Customize from here downwards */
2jQuery(document).ready( function($) {
3	//TODO some backwards compatability here -
4	if( $('#LoginWithAjax').length > 0 ){
5		$('#LoginWithAjax').addClass('lwa');
6		$('#LoginWithAjax_Status').addClass('lwa-status');
7		$('#LoginWithAjax_Register').addClass('lwa-register');
8		$('#LoginWithAjax_Remember').addClass('lwa-remember');
9		$('#LoginWithAjax_Links_Remember').addClass('lwa-links-remember');
10		$('#LoginWithAjax_Links_Remember_Cancel').addClass('lwa-links-remember-cancel');
11		$('#LoginWithAjax_Form').addClass('lwa-form');
12	}
13	/*
14	 * links
15	 * add action input htmls
16	 */
17	//Remember and register form AJAX
18	$('form.lwa-form, form.lwa-remember, div.lwa-register form').submit(function(event){
19		//Stop event, add loading pic...
20		event.preventDefault();
21		var form = $(this);
22		var statusElement = form.find('.lwa-status');
23		if( statusElement.length == 0 ){
24			statusElement = $('<span class="lwa-status"></span>');
25			form.prepend(statusElement);
26		}
27		var ajaxFlag = form.find('.lwa-ajax');
28		if( ajaxFlag.length == 0 ){
29			ajaxFlag = $('<input class="lwa-ajax" name="lwa" type="hidden" value="1" />');
30			form.prepend(ajaxFlag);
31		}
32		$('<div class="lwa-loading"></div>').prependTo(form);
33		//Make Ajax Call
34		var form_action = form.attr('action');
35		if( typeof LWA !== 'undefined' ) form_action = LWA.ajaxurl;
36		$.ajax({
37			type : 'POST',
38			url : form_action,
39			data : form.serialize(),
40			success : function(data){
41				lwaAjax( data, statusElement );
42				$(document).trigger('lwa_' + data.action, [data, form]);
43			},
44			error : function(){ lwaAjax({}, statusElement); },
45			dataType : 'jsonp'
46		});
47		//trigger event
48	});
49
50	//Catch login actions
51	$(document).on('lwa_login', function(event, data, form){
52		if(data.result === true){
53			//Login Successful - Extra stuff to do
54			if( data.widget != null ){
55				$.get( data.widget, function(widget_result) {
56					var newWidget = $(widget_result);
57					form.parent('.lwa').replaceWith(newWidget);
58					var lwaSub = newWidget.find('.').show();
59					var lwaOrg = newWidget.parent().find('.lwa-title');
60					lwaOrg.replaceWith(lwaSub);
61				});
62			}else{
63				if(data.redirect == null){
64					window.location.reload();
65				}else{
66					window.location = data.redirect;
67				}
68			}
69		}
70	});
71
72	//Registration overlay
73	$('.lwa-modal').each( function(i,e){
74		var modal = $(e);
75		modal.parents('.lwa').data('modal', modal);
76		$('body').append($('<div class="lwa"></div>').append(modal));
77	});
78	$(document).on('click', ".lwa-links-modal",  function(e){
79		var target = $(this).parents('.lwa').data('modal');
80		if( typeof target != 'undefined' && target.length > 0 ){
81			e.preventDefault();
82			target.reveal({
83				modalbgclass: 'lwa-modal-bg',
84				dismissmodalclass: 'lwa-modal-close'    //the class of a button or element that will close an open modal
85			});
86		}
87	});
88	//Register
89	$('.lwa-links-register-inline').on('click', function(event){
90		var register_form = $(this).parents('.lwa').find('.lwa-register');
91		if( register_form.length > 0 ){
92			event.preventDefault();
93			register_form.show('slow');
94			$(this).parents('.lwa').find('.lwa-remember').hide('slow');
95		}
96	});
97	$('.lwa-links-register-inline-cancel').on('click', function(event){
98		event.preventDefault();
99		$(this).parents('.lwa-register').hide('slow');
100	});
101
102	//Visual Effects for hidden items
103	//Remember
104	$(document).on('click', '.lwa-links-remember', function(event){
105		var remember_form = $(this).parents('.lwa').find('.lwa-remember');
106		if( remember_form.length > 0 ){
107			event.preventDefault();
108			remember_form.show('slow');
109			$(this).parents('.lwa').find('.lwa-register').hide('slow');
110		}
111	});
112	$(document).on('click', '.lwa-links-remember-cancel', function(event){
113		event.preventDefault();
114		$(this).parents('.lwa-remember').hide('slow');
115	});
116
117	//Handle a AJAX call for Login, RememberMe or Registration
118	function lwaAjax( data, statusElement ){
119		$('.lwa-loading').remove();
120		statusElement = $(statusElement);
121		if(data.result === true){
122			//Login Successful
123			statusElement.removeClass('lwa-status-invalid').addClass('lwa-status-confirm').html(data.message); //modify status content
124		}else if( data.result === false ){
125			//Login Failed
126			statusElement.removeClass('lwa-status-confirm').addClass('lwa-status-invalid').html(data.error); //modify status content
127			//We assume a link in the status message is for a forgotten password
128			statusElement.find('a').on('click', function(event){
129				var remember_form = $(this).parents('.lwa').find('form.lwa-remember');
130				if( remember_form.length > 0 ){
131					event.preventDefault();
132					remember_form.show('slow');
133				}
134			});
135		}else{
136			//If there already is an error element, replace text contents, otherwise create a new one and insert it
137			statusElement.removeClass('lwa-status-confirm').addClass('lwa-status-invalid').html('An error has occured. Please try again.'); //modify status content
138		}
139	}
140
141});
142
143/* http://zurb.com/playground/reveal-modal-plugin */
144/*
145 * jQuery Reveal Plugin 1.0
146 * www.ZURB.com
147 * Copyright 2010, ZURB
148 * Free to use under the MIT license.
149 * http://www.opensource.org/licenses/mit-license.php
150*/
151
152(function($) {
153
154	/*---------------------------
155	 Defaults for Reveal
156	----------------------------*/
157
158	/*---------------------------
159	 Listener for data-reveal-id attributes
160	----------------------------*/
161
162	$('a[data-reveal-id]').on('click', function(e) {
163		e.preventDefault();
164		var modalLocation = $(this).attr('data-reveal-id');
165		$('#'+modalLocation).reveal($(this).data());
166	});
167
168	/*---------------------------
169	 Extend and Execute
170	----------------------------*/
171
172	$.fn.reveal = function(options) {
173
174
175		var defaults = {
176			animation: 'fadeAndPop', //fade, fadeAndPop, none
177			animationspeed: 300, //how fast animtions are
178			closeonbackgroundclick: true, //if you click background will modal close?
179			dismissmodalclass: 'close-reveal-modal', //the class of a button or element that will close an open modal
180			modalbgclass : 'reveal-modal-bg'
181		};
182
183		//Extend dem' options
184		var options = $.extend({}, defaults, options);
185
186		return this.each(function() {
187
188			/*---------------------------
189			 Global Variables
190			----------------------------*/
191			var modal = $(this),
192				topMeasure  = parseInt(modal.css('top')),
193				topOffset = modal.height() + topMeasure,
194				locked = false,
195				modalBG = $('.'+options.modalbgclass);
196
197			/*---------------------------
198			 Create Modal BG
199			----------------------------*/
200			if(modalBG.length == 0) {
201				modalBG = $('<div class="'+options.modalbgclass+'" />').insertAfter(modal);
202			}
203			if( modal.find('.'+options.dismissmodalclass).length == 0 ){
204				modal.append('<a class="'+options.dismissmodalclass+'">&#215;</a>');
205			}
206
207			/*---------------------------
208			 Open & Close Animations
209			----------------------------*/
210			//Entrance Animations
211			modal.bind('reveal:open', function () {
212				modalBG.unbind('click.modalEvent');
213				$('.' + options.dismissmodalclass).unbind('click.modalEvent');
214				if(!locked) {
215					lockModal();
216					if(options.animation == "fadeAndPop") {
217						modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible', 'display':'block'});
218						modalBG.fadeIn(options.animationspeed/2);
219						modal.delay(options.animationspeed/2).animate({
220							"top": $(document).scrollTop()+topMeasure + 'px',
221							"opacity" : 1
222						}, options.animationspeed,unlockModal());
223					}
224					if(options.animation == "fade") {
225						modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure, 'display':'block'});
226						modalBG.fadeIn(options.animationspeed/2);
227						modal.delay(options.animationspeed/2).animate({
228							"opacity" : 1
229						}, options.animationspeed,unlockModal());
230					}
231					if(options.animation == "none") {
232						modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure, 'display':'block'});
233						modalBG.css({"display":"block"});
234						unlockModal()
235					}
236				}
237				modal.unbind('reveal:open');
238			});
239
240			//Closing Animation
241			modal.bind('reveal:close', function () {
242				if(!locked) {
243					lockModal();
244					if(options.animation == "fadeAndPop") {
245						modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
246						modal.animate({
247							"top":  $(document).scrollTop()-topOffset + 'px',
248							"opacity" : 0
249						}, options.animationspeed/2, function() {
250							modal.css({'top':topMeasure, 'opacity' : 1, 'visibility' : 'hidden'});
251							unlockModal();
252						});
253					}
254					if(options.animation == "fade") {
255						modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
256						modal.animate({
257							"opacity" : 0
258						}, options.animationspeed, function() {
259							modal.css({'opacity' : 1, 'visibility' : 'hidden', 'top' : topMeasure});
260							unlockModal();
261						});
262					}
263					if(options.animation == "none") {
264						modal.css({'visibility' : 'hidden', 'top' : topMeasure});
265						modalBG.css({'display' : 'none'});
266					}
267				}
268				modal.unbind('reveal:close');
269			});
270
271			/*---------------------------
272			 Open and add Closing Listeners
273			----------------------------*/
274			//Open Modal Immediately
275			modal.trigger('reveal:open')
276
277			//Close Modal Listeners
278			var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent', function () {
279				modal.trigger('reveal:close')
280			});
281
282			if(options.closeonbackgroundclick) {
283				modalBG.css({"cursor":"pointer"})
284				modalBG.bind('click.modalEvent', function () {
285					modal.trigger('reveal:close')
286				});
287			}
288			$('body').on('keyup', function(e) {
289				if(e.which===27){ modal.trigger('reveal:close'); } // 27 is the keycode for the Escape key
290			});
291
292
293			/*---------------------------
294			 Animations Locks
295			----------------------------*/
296			function unlockModal() {
297				locked = false;
298			}
299			function lockModal() {
300				locked = true;
301			}
302
303		});//each call
304	}//orbit plugin call
305})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.