$(document).ready(function(){var ex_class="";var language=$('.language').val();$('.upload'+ex_class).click(function(){var form=$(this).parent().parent();form.find('input[type=file]').click();});$('textarea').focus(function(){$(this).autosize();/*$(this).parent().find('.up_st').val(0);*/});var error={};error.get=function(number){var errors=$('.js_error').val();errors=errors.split(',');return errors[number];};$('textarea').keyup(function(){var text=$(this).val();if (text.length>=2500){$('.result').html(error.get(2));$('.result').animate({height: '18px'},700);var limited=text.substring(0,2500);$(this).val(limited);$(this).trigger('autosize.resize');}else{$('.result').empty();$('.result').css({height:'0px'});}});$('.save'+ex_class).click(function(){var form=$(this).parent().parent();$.ajax({url:'/'+language+'/?action=form.text',type:'post',dataType:'json',data:form.serialize(),}).done(function(res){$('.result').empty();$('.result').css({height:'0px'});form.find('.links').empty();form.find('.links').css({height:'0px'});if (res.info){$('.result').html(res.info);$('.result').animate({height:'18px'},700);}if(res.links){var height=parseInt(res.links.counter)*20;form.find('.links').html(res.links.text);form.find('.links').animate({height:height+'px'},700);};/*form.find('.up_st').val(0);*/});});$('.refresh'+ex_class).click(function(){var form=$(this).parent().parent();form.find('input[name=token]').val(1);$.ajax({url:'/'+language+'/?action=form.refresh',type:'post',dataType:'json',data:form.serialize(),}).done(function(msg){if (msg.content)form.parent().html(msg.content);$('.result').empty();$('.result').css({height:"0px"});});});function upload(form_data,form){$.ajax({url: '/'+language+'/?action=form.upload_files',type: 'POST',xhr:function(){var myXhr = $.ajaxSettings.xhr();if(myXhr.upload){myXhr.upload.addEventListener('progress',function(e){progress(e,form)},false);}return myXhr;},beforeSend: function(){form.find('progress').show();},success:function(res){form.find('.preview').html(res.content);form.find('progress').attr({value:0});form.find('progress').hide();form.css({'background-color':'#fff'});if(res.info){$('.result').empty();$('.result').css({height:"0px"});$('.result').html(res.info);$('.result').animate({ height:'18px'},700);}else form.find('.up_st').val(1);},data:form_data,dataType:'json',cache:false,contentType:false,processData:false});}$(':file').on('change', function(e){var files=e.target.files;var form=$(this).parent().parent();var form_data = new FormData(form[0]);var jj=0;var exceed=0;var report='';for (var i=0,f;f=files[i];i++){if (f.size<50*1024*1024){form_data.append('img[]',files[i]);jj++;}else{if (exceed)report=report+', ';report=report+f.name;exceed++;}}if (jj)upload(form_data,form);if (exceed){if(exceed>1)report=report+error.get(1);else report=report+error.get(0);$('.result').empty();$('.result').css({height:"0px"});$('.result').html(report);$('.result').animate({height:'18px'},700);}});$(':file').click(function(){$(this).val('');});$('form').on('dragover',function(){$(this).css({'background-color':'#eee'});return false;});$('form').on('dragleave',function(){$(this).css({'background-color':'#fff'});return false;});$('form.'+$('.language').val()+ex_class).on('drop',function(e){e.preventDefault();var files = e.originalEvent.dataTransfer.files;if (typeof(files)=='undefined')$(this).css({'background-color':'#fff'});else{var form=$(this);var form_data = new FormData(form[0]);var jj=0;var exceed=0;var report='';for (var i=0,f;f=files[i];i++){if (f.size<50*1024*1024){form_data.append('img[]',files[i]);jj++;}else{if(exceed)report=report+', ';report=report+f.name;exceed++;}}if (jj)upload(form_data,form);else{$('form').css({'background-color':'#fff'});if (exceed){if(exceed>1)report=report+error.get(1);else report=report+error.get(0);$('.result').empty();$('.result').css({height:'0px'});$('.result').html(report);$('.result').animate({height:'18px'},700);}}}});});function progress(e,form){if(e.lengthComputable){form.find('progress').attr({value:e.loaded,max:e.total});}}