Current File : /home/pacjaorg/www/kmm/components/com_djclassifieds/assets/djuploader.js
/**
 * @package DJ-Classifieds
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email: contact@dj-extensions.com
 */

 function startUpload(up,files)
 {
	 up.start();
 }
 
 function injectUploaded(up,file,info,site_url,label_generator,upload_path)
 {
	 upload_path = (typeof upload_path !== 'undefined') ?  upload_path : '/tmp/djupload';
	 
	 var response = JSON.parse(info.response);
	 if(!response){
		 file.status = plupload.FAILED;
		 file.name += " - File can't be uploaded";
		 jQuery('#'+file.id).addClass('ui-state-error');
		 jQuery('#'+file.id).find('td.plupload_file_name').append(" - File can't be uploaded");
		 return false;
	 }
	 if(response.error) {
		 file.status = plupload.FAILED;
		 file.name += ' - ' + response.error.message;
		 jQuery('#'+file.id).addClass('ui-state-error');
		 jQuery('#'+file.id).find('td.plupload_file_name').append(' - ' + response.error.message);
		 return false;
	 }
	 
	 var img_caption = '';
	 if(label_generator==1){
		 img_caption = stripExt(file.name);
	 }
	 var html = '<img src="'+site_url+upload_path+'/'+file.target_name+'" alt="'+file.name+'" />';
	 html += '	<div class="imgMask">';
	 html += '	<input type="hidden" name="img_id[]" value="0">';
	 html += '	<input type="hidden" name="img_image[]" value="'+file.target_name+';'+file.name+'">';
	 html += '	<input type="hidden" name="img_rotate[]" class="input_rotate" value="0">';
	 html += '	<input type="text" class="itemInput editTitle" name="img_caption[]" value="'+img_caption+'">';
	 html += '	<span class="delBtn"></span><span rel="'+upload_path+'/'+file.target_name+'" alt="'+file.name+'" class="rotateBtn"></span></div>';
	 //var item = jQuery('div',{'class':'itemImage', html: html});
	 var item = jQuery('<div class="itemImage">'+html+'</div>');
	 initItemEvents(item, jQuery('.adminItemImages').length ? true : false);
	 // add uploaded image to the list and make it sortable
	 item.appendTo(jQuery('#itemImagesWrap #itemImages'));
	 if(typeof this.djsortables !== 'undefined'){
		this.djsortables.append(item);
	 }
	 up.removeFile(file);
 
	 if(up.total.queued == 0)
	 {
		 jQuery('#submit_button').prop('disabled', false);
	 }
	 
	 return true;
 }
 
 function injectFrontUploaded(up,file,info,site_url,label_generator,upload_path)
 {
	 injectUploaded(up,file,info,site_url,label_generator,upload_path);
	 if(typeof djImgReqHelper === 'function') djImgReqHelper();
 }
 
 function initItemEvents(item, is_admin)
 {
	 is_admin = (typeof is_admin !== 'undefined') ?  is_admin : false;
	 item = jQuery(item);
	 if(!item.length) return;
	 item.find('.delBtn').on('click',function(){
		 item.detach();
		 if(typeof djImgReqHelper === 'function') djImgReqHelper();
		 return false;
	 });
	 
	 var img_rotate = 0;
	 var image = item.find('img');
	 var img_src_org = image.attr('src');

	 if(item.find('.rotateBtn').length){
		 item.find('.rotateBtn').on('click',function(btn){
			 img_src = jQuery(this).attr('rel');		
			  
			 if(parseInt(jQuery(this).parent().find('[name="img_id[]"]').val())){
				 img_rotate++;
				 item.find('.input_rotate').val(img_rotate);	
				 jQuery(this).closest('.itemImage').find('img').css('transform', 'rotate('+ 90*img_rotate +'deg)');
				 return false;
			 }
 
			 var data_obj =  {
				 'option': 'com_djclassifieds',
				 'img_src': img_src	
			 };
 
			 if(is_admin){
				 data_obj.task = 'item.rotateImage';
			 }else{
				 data_obj.view = 'additem';
				 data_obj.task = 'rotateImage';
			 }

			 jQuery.ajax({
				 url: 'index.php',
				 type: 'post',
				 data: data_obj
			 }).done(function (response, textStatus, jqXHR){
				 if(textStatus == 'success'){
					 image.removeAttr('src'); 
					 img_rotate++;
					 image.attr('src', img_src_org+'?r='+img_rotate);
					 item.find('.input_rotate').val(img_rotate);
				 }
			 });		
		 });		
	 }
	 
	 item.find('input').each(function(){
		 var input = jQuery(this);
		 input.on('focus',function(){
			 item.addClass('active');
		 });
		 input.on('blur',function(){
			 item.removeClass('active');
		 });
	 });
 }
 
 function stripExt(filename)
 {
	 var pattern = /\.[^.]+$/;
	 return filename.replace(pattern, "");	
 }
 
 jQuery(function(){
	 if(typeof jQuery.fn.sortable != 'undefined'){
		window.djsortables = jQuery('#itemImages').sortable({
			 cancel: '.delBtn,.rotateBtn,input,a',
			 cursor: 'move',
			 opacity: 0.3
		 });
	 }
 
	 jQuery('.itemImage').each(function(){
		 initItemEvents(this, jQuery('.adminItemImages').length ? true : false);
	 });

	 if(typeof djImgReqHelper === 'function') djImgReqHelper();
 });
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

Site will be available soon. Thank you for your patience!