Your IP : 216.73.216.41


Current Path : /home/purehotels/public_html/media/com_easyfolderlistingpro/scripts/
Upload File :
Current File : /home/purehotels/public_html/media/com_easyfolderlistingpro/scripts/eflpMoo.js

/**
* @version		3.0
* @author		Michael A. Gilkes (jaido7@yahoo.com)
* @copyright	Michael Albert Gilkes
* @license		GNU/GPLv3
*

Easy Folder Listing Pro Companion Content Plugin
Copyright (C) 2013-2016 Michael Albert Gilkes (Valor Apps)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Description
* ===========
* These are mootools classes that I made myself.
* 
* Minimum Requirements
* ====================
*  + Mootools Core 1.3.2
*  + Mootools Code 1.3.2.1 Fx.Reveal
*/

/* Notes:
 * 1. Table can ONLY use reveal
 * 2. Lists can use slide OR reveal OR slide+reveal
 */

var EFLPMooTable = new Class({
	Implements: [Options, Events],
	options: {
		speed: 'normal',
		easing: 'sine:in:out',
		collapsed: true
	},
	initialize: function(listname, options) {
		this.listname = listname;
		this.setOptions(options);
		this.setupListing();
	},
	setupListing: function(){
		/* get and process all the table rows */
		$$('#'+this.listname+' tr').each(function(row){
			var identity = row.getProperty('id');
			/* only process rows with an id */
			if (identity)
			{
				/* process all children of this row */
				$$('#'+this.listname+' tr.child-of-'+identity).each(function(childrow){
					/* set the reveal characteristics */
					childrow.set('reveal', { duration: this.options.speed, transition: this.options.easing });
					/* process initial collapse */
					if (this.options.collapsed == true)
					{
						/* collapse the children */
						childrow.dissolve();
					}
				}, this);
				
				/* add events to parent folders */
				if (row.hasClass('trigger'))
				{
					/* Add event to hide/show children */
					row.addEvents({
						'click': (function(){
							var parent = row.getProperty('id');
							$$('#'+this.listname+' tr.child-of-'+parent).each(function(childrow){
								if (childrow.getStyle('display') == 'none')
								{
									childrow.reveal();
								}
								else
								{
									childrow.dissolve();
									this.dissolveDescendents(childrow);
								}
							}, this);
						}).bind(this), 
						/* Add event to change cursor on hover */
						'mouseenter': (function(){ row.setStyle('cursor', 'pointer'); }),
						'mouseleave': (function(){ row.setStyle('cursor', 'default'); })
					});
				}
			}
		}, this);
		
		var collapse = document.id(this.listname+"_collapse");
		var expand = document.id(this.listname+"_expand");
		/* add event for collapse all */
		if (collapse)
		{
			collapse.set('reveal', { duration: 0 });
			if (this.options.collapsed == true)
			{
				collapse.dissolve();
			}
			collapse.addEvent('click', (function(event) {
				event.preventDefault();
				this.collapseAll();
				collapse.dissolve();
				expand.reveal();
			}).bind(this));
		}
		/* add event for collapse all */
		if (expand)
		{
			expand.set('reveal', { duration: 0 });
			if (this.options.collapsed != true)
			{
				expand.dissolve();
			}
			expand.addEvent('click', (function(event) {
				event.preventDefault();
				this.expandAll();
				expand.dissolve();
				collapse.reveal();
			}).bind(this));
		}
	},
	collapseAll: function(){
		$$('#'+this.listname+' tr').each(function(row){
			var classlist = row.getProperty('class');
			if (!classlist) { classlist=""; }
			if (classlist.test('child-of-') == true)
			{
				row.dissolve();
			}
			else
			{
				row.reveal();
			}
		}, this);
	},
	expandAll: function(){
		$$('#'+this.listname+' tr').each(function(row){
			row.reveal();
		}, this);
	},
	dissolveDescendents: function(parent){
		var parent_id = parent.getProperty('id');
		$$('#'+this.listname+' tr.child-of-'+parent_id).each(function(child){
			if (child.getStyle('display') != 'none')
			{
				child.dissolve();
				this.dissolveDescendents(child);
			}
		}, this);
	}
});

var EFLPMooList = new Class({
	Implements: [Options, Events],
	options: {
		speed: 'normal',
		easing: 'sine:in:out',
		collapsed: true
	},
	initialize: function(listname, options) {
		this.listname = listname;
		this.setOptions(options);
		this.setupListing();
	},
	setupListing: function(){
		$$('#'+this.listname+' li').each(function(row){
			var identity = row.getProperty('id');
			
			if (identity)
			{
				$$('#'+this.listname+' li.child-of-'+identity).each(function(childrow){
					childrow.set('reveal', { duration: this.options.speed, transition: this.options.easing });
					if (this.options.collapsed == true)
					{
						childrow.dissolve();
					}
				}, this);
				
				if (row.hasClass('trigger'))
				{
					/* Add event to hide/show children */
					row.addEvents({
						'click': (function(){
							var parent = row.getProperty('id');
							$$('#'+this.listname+' li.child-of-'+parent).each(function(childrow){
								if (childrow.getStyle('display') == 'none')
								{
									childrow.reveal();
								}
								else
								{
									childrow.dissolve();
								}
							}, this);
						}).bind(this), 
						/* Add event to change cursor on hover */
						'mouseenter': (function(){ row.setStyle('cursor', 'pointer'); }),
						'mouseleave': (function(){ row.setStyle('cursor', 'default'); })
					});
				}
			}
		}, this);
		
		var collapse = document.id(this.listname+"_collapse");
		var expand = document.id(this.listname+"_expand");
		/* add event for collapse all */
		if (collapse)
		{
			collapse.set('reveal', { duration: 0 });
			if (this.options.collapsed == true)
			{
				collapse.dissolve();
			}
			collapse.addEvent('click', (function(event) {
				event.preventDefault();
				this.collapseAll();
				collapse.dissolve();
				expand.reveal();
			}).bind(this));
		}
		/* add event for expand all */
		if (expand)
		{
			expand.set('reveal', { duration: 0 });
			if (this.options.collapsed != true)
			{
				expand.dissolve();
			}
			expand.addEvent('click', (function(event) {
				event.preventDefault();
				this.expandAll();
				expand.dissolve();
				collapse.reveal();
			}).bind(this));
		}
	},
	collapseAll: function(){
		$$('#'+this.listname+' li').each(function(row){
			var classlist = row.getProperty('class');
			if (!classlist) { classlist=""; }
			if (classlist.test('child-of-') == true)
			{
				row.dissolve();
			}
			else
			{
				row.reveal();
			}
		}, this);
	},
	expandAll: function(){
		$$('#'+this.listname+' li').each(function(row){
			row.reveal();
		}, this);
	}
});

function eflp_moo_pageoptions(idtext, select) {
	var listingData = document.id(idtext).get('data-listing');
	var token = document.id(idtext).get('data-token');
    var limit = select.options[select.selectedIndex].value;
    var obj = { 'data' : listingData, 'listingId' : idtext, 'pagenumber' : 1, 'pagelimit' : limit , 'token' : token };
	obj[token] = 1;
	var req = new Request.HTML({
			method : 'post',
			url : 'index.php?option=com_easyfolderlistingpro&task=pagination.change&format=raw',
			data : obj,
			update : document.id(idtext).parentNode
		});
	req.send();
}

function eflp_moo_pagination(idtext, pagenumber, pagelimit) {
	var listingData = document.id(idtext).get('data-listing');
	var token = document.id(idtext).get('data-token');
	var obj = { 'data' : listingData, 'listingId' : idtext, 'pagenumber' : pagenumber, 'pagelimit' : pagelimit, 'token' : token };
	obj[token] = 1;
	var req = new Request.HTML({
		method : 'post',
		url : 'index.php?option=com_easyfolderlistingpro&task=pagination.change&format=raw',
		data : obj,
		update : document.id(idtext).parentNode
	});
	req.send();
}

function eflp_moo_explore(idtext, status) {
	var listingData = document.id(idtext).get('data-listing');
	var token = document.id(idtext).get('data-token');
    var obj = { 'data' : listingData, 'listingId' : idtext, 'status' : status , 'token' : token };
	obj[token] = 1;
	var req = new Request.HTML({
		method : 'post',
		url : 'index.php?option=com_easyfolderlistingpro&task=explorer.folder&format=raw',
		data : obj,
		update : document.id(idtext).parentNode
	});
	req.send();
}

var EFLPMooSearch = new Class({
	Implements: [Options, Events],
	options: {
		esc: true,
		wait: 500
	},
	initialize: function(listname, textLength, options) {
		this.listname = listname;
		this.textLength = textLength;
		this.timer = null;
		this.setOptions(options);
		this.setupSearch();
	},
	setupSearch: function(){
		/* Add the delayed search function */
		var textbox = document.id(this.listname+'_textbox');
		if (textbox)
		{
			textbox.addEvent('keyup', (function(event){
				var text = textbox.get('value');
				if (text.length > this.textLength)
				{
					if (this.timer != null)
					{
						clearTimeout(this.timer);
					}
					
					this.timer = this.applyFilter.delay(this.options.wait, this, text);
				}
				else if (text.length == 0)
				{
					this.handleFilterCancel();
				}
			}).bind(this));
		}
		/* Add the ESC key event */
		if (textbox)
		{
			textbox.addEvent('keydown', (function(e){
				if (e.key == 'esc' && this.options.esc == true) //esc = 27
				{
					var text = textbox.get('value');
					if (text.length > 0)
					{
						this.handleFilterCancel();
					}
				}
			}).bind(this));
		}
		/* Add event to the cancel icon */
		var cancelimg = document.id(this.listname+'_cancelimg');
		if (cancelimg)
		{
			cancelimg.set('reveal', { display: 'inline' });
			cancelimg.addEvent('click', this.handleFilterCancel.bind(this));
		}
	},
	applyFilter: function(text){
		/* Send the ajax search and display results */
		var listingData = document.id(this.listname).get('data-listing');
		var token = document.id(this.listname).get('data-token');
		var obj = { 'data' : listingData, 'listingId' : this.listname, 'text' : text };
		obj[token] = 1;
		var req = new Request.HTML({
				method : 'post',
				url : 'index.php?option=com_easyfolderlistingpro&task=search.filter&format=raw',
				data : obj,
				update : document.id(this.listname+'_search_results')
			});
		req.send();
		
		/* Show the cancel button */
		document.id(this.listname+'_cancelimg').reveal();
	},
	handleFilterCancel: function(){
		/* clear the text box */
		document.id(this.listname+'_textbox').set('value', '');
		
		/* clear the search results */
		document.id(this.listname+'_search_results').empty();
		
		/* hide the cancel icon */
		document.id(this.listname+'_cancelimg').dissolve();
		
		/* return focus to text box */
		document.id(this.listname+'_textbox').focus();
	}
});

var EFLPMooLimits = new Class({
	Implements: [Options, Events],
	options: {
		totalsize: 0.0,
		totalnumber: 0,
		maxsize: 10.0, /* size in megabytes */
		maxnumber: 10
	},
	initialize: function(listname, options) {
		this.listname = listname;
		this.setOptions(options);
		this.setupLimits();
	},
	setupLimits: function(){
		window.addEvent('domready', (function() {
			/* hide the limits div */
			document.id(this.listname+'_multidownload_limits').dissolve();
			
			/* disable the multidownload button */
			document.id(this.listname+'_download_button').disabled = true;
		}).bind(this));
	},
	checkFile: function(elem){
		var fsize = elem.get('data-bytes');
		if (elem.checked) {
			this.options.totalsize += parseFloat(fsize);
			this.options.totalnumber += 1;
			this.checkLimits();
		}
		else {
			this.options.totalsize -= parseFloat(fsize);
			if (this.options.totalsize < 0) { this.options.totalsize = 0.0; }
			this.options.totalnumber -= 1;
			if (this.options.totalnumber < 0) { this.options.totalnumber = 0; }
			this.checkLimits();
		}
	},
	checkLimits: function(){
		/* update the text */
		var sizetext = (this.options.totalsize / (1024 * 1024));
		sizetext = sizetext.toFixed(2);
		
		document.id(this.listname+'_totalsize').set('text', sizetext.toString()+' / '+this.options.maxsize.toString()+' MB');
		document.id(this.listname+'_totalnumber').set('text', this.options.totalnumber.toString()+' / '+this.options.maxnumber.toString());
		if (this.options.totalnumber > this.options.maxnumber || this.options.totalsize > (this.options.maxsize * 1024 * 1024))	{
			/* show the limits div */
			document.id(this.listname+'_multidownload_limits').reveal();
			
			/* disable the multidownload button */
			document.id(this.listname+'_download_button').disabled = true;
		}
		else if (this.options.totalnumber == 0) {
			/* hide the limits div */
			document.id(this.listname+'_multidownload_limits').dissolve();
			
			/* disable the multidownload button */
			document.id(this.listname+'_download_button').disabled = true;
		}
		else {
			/* hide the limits div */
			document.id(this.listname+'_multidownload_limits').dissolve();
			
			/* enable the multidownload button */
			document.id(this.listname+'_download_button').disabled = false;
		}
	}
});