b0y-101 Mini Shell


Current Path : E:/www/risk/plugins/content/jmpmodal/assets/
File Upload :
Current File : E:/www/risk/plugins/content/jmpmodal/assets/script.js

(function($){
	$(document).ready(function(){
		$('.jmpModal').each(function(){
			var el=$(this), h='',
				params={
					style:1, 
					open:true, 
					delay:0, 
					perspective:false,
					trigger:false,
					close:'Close me!',
					/**
					overlayColor:'rgba(143,27,15,0.8)',
					modalColor:'#e74c3c',
					textColor:'#fff'
					**/
				};

			// process params;
			if(typeof el.attr('data-style')!='undefined')
				params.style=1*el.attr('data-style');

			if(params.style>=17) params.style=1;

			/**
			if($.inArray(params.style, [17,18,19])!=-1)
				params.perspective=true;
			**/

			if(typeof el.attr('data-delay')!='undefined')
				params.delay=1*el.attr('data-delay');

			if(typeof el.attr('data-open')!='undefined')
				params.open=1*el.attr('data-open')>0;

			var extra=['trigger', 'close', 'overlayColor', 'modalColor', 'textColor'];
			$.each(extra, function(k,v){
				if(typeof el.attr('data-'+v)!='undefined')
					params[v]=el.attr('data-'+v);
			});
			
			h='<div class="jmp-modal">';
				h+='<div class="md-modal md-effect-'+params.style+'">';
					h+='<div class="md-content">';
						h+='<div class="inn"></div>';
						h+='<button class="md-close">'+params.close+'</button>';
					h+='</div>';
				h+='</div>';
				h+='<div class="md-overlay"></div>';
			h+='</div>';

			h=$(h);
			h.insertAfter(el);
			el.removeAttr('class').appendTo(h.find('.inn'));

			// adjust color
			if(params.hasOwnProperty('textColor'))
				h.find('.md-content').css('color', params.textColor);

			if(params.hasOwnProperty('modalColor'))
				h.find('.md-content').css('background', params.modalColor);

			if(params.hasOwnProperty('overlayColor'))
				h.find('.md-overlay').css('background', params.overlayColor);

			var openModal=function(){
				h.find('.md-modal').addClass('md-show');
				if(params.perspective)
					$('html').addClass('md-perspective');
			};

			var closeModal=function(){
				h.find('.md-modal').removeClass('md-show');
				if(params.perspective)
					$('html').removeClass('md-perspective');
			}

			if(params.open)
			{
				if(params.delay>0){
					setTimeout(function(){
						openModal();
					}, params.delay*1000);
				} else {
					openModal();
				}
			}

			if(params.trigger!==false)
			{
				$(document).on('click', params.trigger, function(e){
					e.preventDefault();
					openModal();
				});
			}

			h.on('click', '.md-close, .md-overlay', function(){
				closeModal();
			});
		});
	});
})(jQuery);

Copyright © 2019 by b0y-101