$(document).ready(function () {
$('[data-selcont]').click(function(event){inp_sl(this);event.stopPropagation();return false});
$('[data-selectclick]').click(function(){$(this).select();});
$('.mymod-overlay').click(function(event) {
if ($(event.target).closest(".mymod-modal").length) return;
mymod();
event.stopPropagation();
});
$('[data-scroll]').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({scrollTop : $($anchor.data('scroll')).offset().top - 60}, 600, '');
event.preventDefault();
});
});
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("Copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("Copy");
alert("Текст скопирован!",1)
}
}
function CopyToClipboard_in(containerid){
var copyText = document.getElementById(containerid);
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Текст скопирован!",1);
}
function inp_sl(e){
if(window.getSelection){
var s=window.getSelection();
if(s.setBaseAndExtent){
s.setBaseAndExtent(e,0,e,e.innerText.length-1);
}else{
var r=document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);}
}else if(document.getSelection){
var s=document.getSelection();
var r=document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}else if(document.selection){
var r=document.body.createTextRange();
r.moveToElementText(e);
r.select();}
return false;
}
function mymod(){$('.mymod-overlay').fadeOut(300); return false;}
function mymod_close(e){$(e).fadeOut(300); return false;}
function mymod_show(id){
var el = $('#'+id);
if(el != undefined){ el.fadeIn(300); }
}
function empty(mixed_var){
var t = (
mixed_var === "" ||
/*mixed_var === 0 || */
/*mixed_var === "0" || */
mixed_var === null ||
//isNaN(mixed_var) ||
typeof mixed_var == "undefined" ||
mixed_var === false ||
/^[\s\n\t]*$/im.test(mixed_var+'')
);
return t;
}
function validator(param){
var ret="true";
var ale = "";
var valgroup = $("[data-valgroup=" + param + "]").attr("data-valtype");
$("[data-valgroup=" + param + "]").each(function(indx, element){
$("#" + $(this).attr("data-validel")).removeClass('validator_form_err');
if($("#" + $(this).attr("data-validel")).is(":visible"))
{
if($(this).attr("data-valtype")=="reqired")
{
if(/^[\s\t\n]*$/.test($("#" + $(this).attr("data-validel")).val()))
{
ret = false;
$(this).show();
$("#" + $(this).attr("data-validel")).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
else if($(this).attr("data-valtype")=="reqired_duble")
{
var d_val = $(this).attr("data-validduble").split('|');
var d_bool = false;
for (var i = d_val.length - 1; i >= 0; i--) {
if(!/^[\s\t\n]*$/.test($("#" + d_val[i]).val())){
d_bool = true;
break;
}
}
if(!d_bool)
{
ret = false;
$(this).show();
$("#" + d_val[i]).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
else if($(this).attr("data-valtype")=="email")
{
var elid = $(this).attr("data-validel");
if (!/^\s*$/.test($("#" + elid).val())) {
if(!/^[0-9aA-zZаА-яЯ][0-9aA-zZаА-яЯ\-_\.]*@[0-9aA-zZаА-яЯ\-_]+(?:\.[aA-zZаА-яЯ]+){1,4}$/.test($("#" + elid).val()))
{
ret = false;
$(this).show();
$("#" + $(this).attr("data-validel")).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
}
else if($(this).attr("data-valtype")=="int")
{
if(!/^\d+$/.test($("#" + $(this).attr("data-validel")).val()))
{
ret = false;
$(this).show();
$("#" + $(this).attr("data-validel")).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
else if($(this).attr("data-valtype")=="float")
{
if(!/^[0-9]+([\.\,][0-9]+)?$/.test($("#" + $(this).attr("data-validel")).val()))
{
ret = false;
$(this).show();
$("#" + $(this).attr("data-validel")).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
else if($(this).attr("data-valtype")=="regexp")
{
var elid = $(this).attr("data-validel");
if (!/^\s*$/.test($("#" + elid).val())) {
$reg = new RegExp($("[data-valregexp]").attr("data-valregexp"));
if(!$reg.test($("#" + elid).val()))
{
ret = false;
$(this).show();
$("#" + $(this).attr("data-validel")).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
}
else if($(this).attr("data-valtype")=="equals")
{
var elid = $(this).attr("data-validel");
var confelid = $(this).attr("data-valequalsid");
if (!/^\s*$/.test($("#" + elid).val())) {
if($("#" + elid).val() != $("#" + confelid).val())
{
ret = false;
$(this).show();
$("#" + $(this).attr("data-validel")).addClass('validator_form_err');
$("#" + confelid).addClass('validator_form_err');
if(!/^\s*$/.test($(this).attr("data-valerrormes")))
ale += $(this).attr("data-valerrormes") +"\n";
}
else
{
$(this).hide();
}
}
}
}
});
if(!/^\s*$/.test(ale))
alert(ale);
return ret;
}
function getFormData(e){
var formData = new FormData();
el = $(e).find('input[name], button[name], textarea[name], select[name]');
return _getFormData(formData,el);
}
function getFormData_el(e){
var formData = new FormData();
el = $(e);
return _getFormData(formData,el);
}
function _getFormData(formData,el){
el.each(function()
{
var el = $(this);
if(!empty(el.attr('disabled')))
return;
var type = el.attr('type');
var val = '';
if(type == 'checkbox' || type == 'radio'){
if(!el.prop("checked"))
return;
}
if(type == 'file')
val = el.prop('files')[0];
else
val = el.val();
var name = el.attr('name');
formData.append(name,val);
});
return formData;
}