<commit_before>Package('Sapphire', {

/**********************************************************************************
	Class: PageManager

	This class is used by the <Application> class to manage pages and dialogs.
	Applications have no need to use this class directly

	Extends:
		<Eventer>

	See Also:
		<Application>
*/
	PageManager : new Class({
		Extends : Sapphire.Eventer,

	/**********************************************************************************
		Constructor: initialize

		This is the constructor for the class.

		Parameters:
			exclusive     - true if only one page at a time can be shown, false otherwise

	*/
		initialize: function(exclusive)
		{
			this.parent();
			this.exclusive = exclusive;
			this.pages = $({});
			this.currentPage = undefined;
			this.showEffect = function (oldPage, newPage, callback) {callback()};
			this.hideEffect = function (oldPage, newPage, callback) {callback()};
		},

	/**********************************************************************************
		Method: setContainer

		Called to set the DOM element within which all the pages will be kept. Pages will
		be pulled out of the DOM and moved under this node. All previous content in this
		element will be deleted.

		Parameters:
			container     - The DOM node to put the pages in

	*/
		setContainer : function(container)
		{
			this.container = container;
		},

	/**********************************************************************************
		Method: addPage

		This method adds a page to the list of pages to be named.

		Parameters:
			name        - The name of the page
			spec        - information about the page itself
	*/
		addPage : function(spec)
		{
			this.pages[spec.name] = $H(spec);
		},

	/**********************************************************************************
		Method: afterShowEffect

		This function is passed to the show effect callback. When an effect
		has completed, it must call this callback.

		Parameters:
			name        - The name of the page
			passed      - the variables that were passed to the show method

		Fires:
			- firstShow
			- show
			- show.<name>
	*/
		afterShowEffect : function(oldPage, newPage, passed)
		{
			var name = newPage.name;
			var page = newPage;

			page.selector.css('display', 'block');

			if (oldPage && this.currentPage != name) this.hidePage(oldPage.name, name);
			else
			{
			// There is no page to hide, so the animation is over
				this.fire('postAnimate.' + name);
				this.fire('postAnimate', name);
				this.transitioning = false;
			}

			this.currentPage = newPage.name;
		},

	/**********************************************************************************
		Method: showPage

		The application manager calls this method to show a page or dialog. If
		exclusive is true, then the current page will be hidden first.

		Parameters:
			name        - The name of the page
			passed      - the variables that were passed to the show method of the application
	*/
		showPage : function(name, passed)
		{
			var page = this.pages[name];
			var canShow = true;
			var passedJSON = JSON.stringify(passed);
			var oldPage = null;
			var oldPageSelector = null;
			var newPage = page;

			if (page == undefined) return;

			if (this.transitioning) return;

			this.fire('canShow', name, function(can)
			{
				canShow = canShow && can;
			}.bind(this));
			if (!canShow) return;

			this.loadPage(name, function(loaded)
			{
			// Remove the current page if needed
				if (this.currentPage == name && passedJSON == this.passedJSON)
				{
					return;
				}

				this.transitioning = true;
				if (this.currentPage && this.exclusive)
				{
					oldPage = this.pages[this.currentPage];
					oldPageSelector = oldPage.selector
				}

				//this.currentPage = name;
				this.passedJSON = passedJSON

			//!Pending: should we increment z-order here?
				if (!page.dontPrune || !page.shown)
				{
					this.container.append(page.selector);
					page.shown = true;
				}

				if (loaded)
				{
					this.fire('load', page.selector);
					this.fire('load.' + name);
				}

				this.oldPage = oldPage;
				this.newPage = newPage;

				if (!page.shown)
					this.fireArgs('firstShow.' + name, passed);

				page.shown = true;
				this.fireArgs('show.' + name, passed);
				this.fireArgs('preAnimate.' + name, passed);
				passed.splice(0, 0, name)
				this.fireArgs('show', passed);
				this.fireArgs('preAnimate', passed);

				this.showEffect(oldPageSelector, page.selector, this.afterShowEffect.bind(this, oldPage, newPage, passed));
			}.bind(this));<commit_msg>- adding page name as class on body<commit_after>Package('Sapphire', {

/**********************************************************************************
	Class: PageManager

	This class is used by the <Application> class to manage pages and dialogs.
	Applications have no need to use this class directly

	Extends:
		<Eventer>

	See Also:
		<Application>
*/
	PageManager : new Class({
		Extends : Sapphire.Eventer,

	/**********************************************************************************
		Constructor: initialize

		This is the constructor for the class.

		Parameters:
			exclusive     - true if only one page at a time can be shown, false otherwise

	*/
		initialize: function(exclusive)
		{
			this.parent();
			this.exclusive = exclusive;
			this.pages = $({});
			this.currentPage = undefined;
			this.showEffect = function (oldPage, newPage, callback) {callback()};
			this.hideEffect = function (oldPage, newPage, callback) {callback()};
		},

	/**********************************************************************************
		Method: setContainer

		Called to set the DOM element within which all the pages will be kept. Pages will
		be pulled out of the DOM and moved under this node. All previous content in this
		element will be deleted.

		Parameters:
			container     - The DOM node to put the pages in

	*/
		setContainer : function(container)
		{
			this.container = container;
		},

	/**********************************************************************************
		Method: addPage

		This method adds a page to the list of pages to be named.

		Parameters:
			name        - The name of the page
			spec        - information about the page itself
	*/
		addPage : function(spec)
		{
			this.pages[spec.name] = $H(spec);
		},

	/**********************************************************************************
		Method: afterShowEffect

		This function is passed to the show effect callback. When an effect
		has completed, it must call this callback.

		Parameters:
			name        - The name of the page
			passed      - the variables that were passed to the show method

		Fires:
			- firstShow
			- show
			- show.<name>
	*/
		afterShowEffect : function(oldPage, newPage, passed)
		{
			var name = newPage.name;
			var page = newPage;

			page.selector.css('display', 'block');

			if (oldPage && this.currentPage != name) this.hidePage(oldPage.name, name);
			else
			{
			// There is no page to hide, so the animation is over
				this.fire('postAnimate.' + name);
				this.fire('postAnimate', name);
				this.transitioning = false;
			}

			this.currentPage = newPage.name;
		},

	/**********************************************************************************
		Method: showPage

		The application manager calls this method to show a page or dialog. If
		exclusive is true, then the current page will be hidden first.

		Parameters:
			name        - The name of the page
			passed      - the variables that were passed to the show method of the application
	*/
		showPage : function(name, passed)
		{
			var page = this.pages[name];
			var canShow = true;
			var passedJSON = JSON.stringify(passed);
			var oldPage = null;
			var oldPageSelector = null;
			var newPage = page;

			if (page == undefined) return;

			if (this.transitioning) return;

			this.fire('canShow', name, function(can)
			{
				canShow = canShow && can;
			}.bind(this));
			if (!canShow) return;

			this.loadPage(name, function(loaded)
			{
			// Remove the current page if needed
				if (this.currentPage == name && passedJSON == this.passedJSON)
				{
					return;
				}

				this.transitioning = true;
				if (this.currentPage && this.exclusive)
				{
					$(document.body).removeClass(this.currentPage);

					oldPage = this.pages[this.currentPage];
					oldPageSelector = oldPage.selector
				}

				if (this.exclusive)
					$(document.body).addClass(name);
				//this.currentPage = name;
				this.passedJSON = passedJSON

			//!Pending: should we increment z-order here?
				if (!page.dontPrune || !page.shown)
				{
					this.container.append(page.selector);
					page.shown = true;
				}

				if (loaded)
				{
					this.fire('load', page.selector);
					this.fire('load.' + name);
				}

				this.oldPage = oldPage;
				this.newPage = newPage;

				if (!page.shown)
					this.fireArgs('firstShow.' + name, passed);

				page.shown = true;
				this.fireArgs('show.' + name, passed);
				this.fireArgs('preAnimate.' + name, passed);
				passed.splice(0, 0, name)
				this.fireArgs('show', passed);
				this.fireArgs('preAnimate', passed);

				this.showEffect(oldPageSelector, page.selector, this.afterShowEffect.bind(this, oldPage, newPage, passed));
			}.bind(this));
{'fraction_non_alphanumeric': 0.2029126213592233, 'fraction_numerical': 0.0004314994606256742, 'mean_word_length': 3.264489420423183, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2254315', 'n_tokens_mistral': 3188, 'n_tokens_neox': 2547, 'n_words': 816}