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


	var CHECKMARK = String.fromCharCode(parseInt(2713, 16)); //add checkmark character to forms

	window.SkyPrep = window.SkyPrep || {};
	var SkyPrep = window.SkyPrep;
	SkyPrep.api = SkyPrep.api || {}
	var api = SkyPrep.api;

	api.ajaxSetup = $.ajaxSetup;

	var stamp_user_signature_id;
	var autoclear_stamp_user_signature_id = true;


	api.setUserSignatureId = function(id, autoclear) {
		stamp_user_signature_id = id;
		autoclear_stamp_user_signature_id = autoclear;
	}

	api.clearUserSignatureId = function() {
		stamp_user_signature_id = null;
	}

	api.requestUserSignature = function(description) {
		return $.when();
	}

	api.ajaxSubmit = function(form) {
		var $form = $(form);
		var form_params = $form.serialize();
		var method = $form.attr('method') || 'post';
		var url = $form.attr('action');
		return api.ajax({
			"method" : method,
			"url" : url,
			"data" : form_params
		});

	}


	//Dummy function to show popup window to request password
	api.challengeForCredentials = function() {
		var d = $.Deferred();
		var $form = $('#password-confirmation-for-session-form');
		var $modal = $('#password-confirmation-for-session-modal')
		var $cancelBtn = $('#cancel-password-confirmation-for-session-modal');
		var undoFormBehavioursFn, modalCheckIfVisibleInterval;
		var $passwordField = $('#confirm-password-for-session-password-field')

		$passwordField.focus();

		var submitHandler = function() {
			$form.ajaxSubmit({
				"success" : function() {
					$modal.modal('hide');
					undoFormBehavioursFn();
					d.resolve();
				},
				"error" : function() {
					notify('Please try again.');
				}
			});
			return false;
		};

		undoFormBehavioursFn = _.once(function() {
			$cancelBtn.unbind('click');
			$form.unbind('submit', submitHandler);
			if (modalCheckIfVisibleInterval) {
				cancelInterval(modalCheckIfVisibleInterval)
			}
			console.log('cancelling challengeModal behaviour');
		});

		$cancelBtn.click(function() {
			undoFormBehavioursFn();
			$modal.modal('hide');
			return false;
		})

		var checkIfPopupClosed = function() {
			if (!$modal.is(':visible')) {
				undoFormBehavioursFn();
			}
		};

		setInterval(checkIfPopupClosed, 500);

		$form.submit(submitHandler);

		$modal.modal({backdrop: 'static', keyboard: false});
		//$('#password-confirmation-for-session-modal').modal('show');


		return d.promise();

	}

	api.ajax = function(opts) {
		opts = (typeof(opts) === 'undefined' ? {} : opts);
		var method = opts.method || opts.type || 'post';
		method = $.trim(method.toLowerCase());

		opts.method = method;
		opts.type = method;

		var data = opts.data || {};

		data.utf8 = CHECKMARK;
		// Check the line below

		if (!_.isNil(stamp_user_signature_id)) {
			data.stamp_user_signature_id = stamp_user_signature_id;
		}

		if (autoclear_stamp_user_signature_id) {
			stamp_user_signature_id = null;
		}
		opts.headers = opts.headers || {}
		opts.headers['X-SkyPrep-Theme'] = opts.headers['X-SkyPrep-Theme'] || 'barnie';

		if (  (['post', 'put', 'delete' ].indexOf(method) &gt;= 0) || (_.startsWith(opts.url, '/admin/api/')))  {
			data['authenticity_token'] = SkyPrep.form_auth_token;
			opts.headers['X-Auth-Token'] = SkyPrep.form_auth_token;
		}

		opts.data = data;

		if (_.toLower(opts.postAs) == 'json') {
			opts.data = JSON.stringify(data);
			opts.contentType = "application/json; charset=UTF-8";
		}


		var handlePasswordConfirmError = function(respObj, errorTextStatus, errorThrown) {
			var shouldChallengeForCredentials = respObj.getResponseHeader('X-SkyPrep-Challenge-Credentials-For-Session');
			if (shouldChallengeForCredentials == '1') {
				SkyPrep.api.challengeForCredentials().then(function() {
					return SkyPrep.api.ajax(opts);
				})
			}
		};

		if (opts.error) {
			var cur_errfn = opts.error;
			opts.error = function() {
				var args = _.map(arguments);

				var respObj = _.first(arguments);
				var shouldChallengeForCredentials = respObj.getResponseHeader('X-SkyPrep-Challenge-Credentials-For-Session');
				if (shouldChallengeForCredentials == '1') {
					handlePasswordConfirmError.apply(this, args);
				} else {
					cur_errfn.apply(this, args);
				}
			}
		} else {
			opts.error = handlePasswordConfirmError;
		}


		return $.ajax(opts)
	};

	api.get = api.ajax; //alias


	api.post = function(opts) {
		opts = (typeof(opts) === 'undefined' ? {} : opts);
		var method = 'post';


		opts['method'] = method;
		opts['type'] = method;
		return api.ajax(opts);
	};

	//Does a POST and expects JSON data as response
	api.jsonPost = function(opts) {
		opts = (typeof(opts) === 'undefined' ? {} : opts);
		opts.data = opts.data || {};
		opts.data['format'] = 'json';
		opts.dataType = 'json';
		opts.format = 'json';
		return api.post(opts);

	}

	api.postJson = api.jsonPost;

	//Does a GET and expects JSON data as response

	api.jsonGet = function(opts) {
		opts = (typeof(opts) === 'undefined' ? {} : opts);
		opts.data = opts.data || {};
		opts.data['format'] = 'json';
		opts.dataType = 'json';
		opts.format = 'json';
		return api.get(opts);

	}

	api.getJson = api.jsonGet;


})(jQuery);
</pre></body></html>