jQuery('.buttonArrowRight').on('click', function (){ sendGa(); });
function sendGa(){
if(!('ga' in window)){
return;
}
try {
ga('send', {
hitType: 'event',
eventCategory: 'Test',
eventAction: 'play',
eventLabel: 'Fall Campaign'
});
} catch (e){
console.error('sendGa Error', e);
}}
function sendEndGa(){
if(!('ga' in window)){
return;
}
try {
ga('send', {
hitType: 'event',
eventCategory: 'Test',
eventAction: 'end',
eventLabel: 'Fall Campaign'
});
} catch (e){
console.error('sendEndGa Error', e);
}}
function sendMailTestResult(){
var email='';
var subject='Результат теста';
var emailBody=$(stripScripts($('#descTest').html()).replace(/<\/li>/gi, '\n')).text().replace(/,/gi, ' ').replace(/\n/gi, '%0A');
window.location='mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
}
function stripScripts(s){
var div=document.createElement('div');
div.innerHTML=s;
var scripts=div.getElementsByTagName('script');
var i=scripts.length;
while (i--){
scripts[i].parentNode.removeChild(scripts[i]);
}
return div.innerHTML;
}
function printTestResult(){
var html_to_print=$('#descTest').html();
var iframe=$('<iframe id="print_frame">');
$('body').append(iframe);
var doc=$('#print_frame')[0].contentDocument||$('#print_frame')[0].contentWindow.document;
var win=$('#print_frame')[0].contentWindow||$('#print_frame')[0];
doc.getElementsByTagName('body')[0].innerHTML=html_to_print;
win.print();
$('iframe#print_frame').remove();
}
$('.buttonArrow.lastButton').click(function (){
if($('input[name=feeeeee]:checked').length===1){
$(this).removeClass('lastButton');
}});
var numQuest=0,
numberQuestnToTitle=0,
resultTests='',
idQuestion,
prOprosID;
setInterval(function (){
if(numQuest==0){
$('.firstButton').addClass('disabled');
}else{
$('.firstButton').removeClass('disabled');
}
if($('input[name=feeeeee]:checked').length===0){
$('.lastButton').addClass('disabled');
$('.lastButton').click(false);
}else{
$('.lastButton').removeClass('disabled');
}}, 500);
var param='get';
$("input[name=feeeeee]").on("ifChanged", function (){
classAjax.sendTest();
});
var x2js=new X2JS();
var classAjax={
urlAspx: window['shortcodeTest2-IMTurlRemote'] ?
window['shortcodeTest2-IMTurlRemote'] :
'https://www.zdorovieinfo.ru/ajax/opros_test_questions.php',
initTest: function (){
$('#barPosition').hide();
$('#buttonForMovie').html('<input type="button" class="buttonArrow buttonBegin" onclick="classAjax.initTesting()" ' +
' value="Начать тест"/>');
},
generatQuest: function (obj){
var html="";
var answers=obj.root.Question.answers.Answer;
if(!Array.isArray(answers)){
answers=[answers];
}
for (var i in answers){
var answer=answers[i];
var answerText='';
if(answer.__text!==undefined){
answerText=answer.__text.replace(/\{quotes\}/g, '\'')
.replace(/\{double_quotes\}/g, '\"').replace(/\{right_slash\}/g, '\/')
.replace(/\{less\}/g, '<').replace(/\{more\}/g, '>');
}
var typeCheckAnswer=(obj.root.Question._typeQuestion==="2408600") ? 'checkbox':'radio';
if(obj.root.Question._typeWidget==='10594912'){
typeCheckAnswer='select';
}
if(answer._type==='2408818'){
html +='<label style="display: -webkit-inline-box;" for="icheck' + answer._pos + '"> ' +
' <input id="icheck' + answer._pos + '" ' +
' type="radio" class="icheck" name="feeeeee" value="' + answer._pos + '" ';
if(answer._Value==='1'||answer._Value==='1'){
html +=' checked ';
}
html +=' >' +
'<input type="text" name="feeeeee" class="form-control inputValueAnswer" id="icheck' + answer._pos + '">' +
'&nbsp;  ' + answerText + '</label> <br/>';
}else if(answer._type==='2408817'){
var checkAnswerText='';
if(answerText!=''||answerText!=undefined){
checkAnswerText='<span class="label_text">  ' + answerText + '</span>';
}
html +='<label  style="width: 70%;" for="icheck' + answer._pos + '"> ' +
' <input id="text' + answer._pos + '"  style="margin-left: 20%; margin-top: 20px; " ' +
' type="text" class="" name="feeeeee" value="' + answer._Value + '" ' +
'<br/>';
}else if(answer._type==='14301043'){
html +="<div class=\"col-xs-12 col-sm-6 col-md-4 col-lg-4\">" +
' <input id="icheck' + answer._pos + '" ' +
' type="' + typeCheckAnswer + '" class="icheck " name="feeeeee" value="' + answer._pos + '" ';
if(answer._Value==='1'||answer._Value==='1'){
html +=' checked ';
}
html +=' >' +
'<label style="display: -webkit-inline-box;" for="icheck' + answer._pos + '">' +
'<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">';
html +=" <div class=\"col-xs-10 col-sm-11 col-md-11 col-lg-11 imageAnswer\" style=\"padding-top: 150px;background-image: url('http://old.zdorovieinfo.ru/" + answer._ImageSrc + "');\"> ";
html +=" <div class=\"col-xs-12 col-sm-12 col-md-12 col-lg-12\" style=\"padding: 0;margin:0!important;\"> " + answerText + " </div></div></div></label> </div>";
}else if(answer._type==='2408816'&&typeCheckAnswer==='select'){
if(i==0){
html +="<div class=\"form-group\" style=\"min-height: 30px;\">" +
"<div class=\"col-sm-12\">" +
"<select name=\"feeeeee\" id=\"inputID\"  style=\"margin-top: 50px;margin-bottom: 50px;\" class=\"form-control\">";
}
var selected='';
if(answer._Value==='1'||answer._Value==='1'){
selected=' selected ';
}
html +="<option value=\"" + answer._pos + "\" " + selected + "> " + answerText + "</option>";
if(i==answers.length - 1){
html +="</select>" +
"</div>" +
"</div>";
}}else{
html +='<label for="icheck' + answer._pos + '"> ' +
' <input id="icheck' + answer._pos + '" ' +
' type="' + typeCheckAnswer + '" class="icheck " name="feeeeee" value="' + answer._pos + '" ';
if(answer._Value==='1'||answer._Value==='1'){
html +=' checked ';
}
html +=' ><span class="label_text">  ' + answerText +
'</span></label> <br/>';
}}
if(obj.root.Question._imageUrl!==""&&obj.root.Question._typeQuestion=="13536156"){
$('#flashMovie .header-title').after(function (indx){
return '<div style=" background-repeat: no-repeat; background-size: 75%;min-height: 570px; background-position: 50% 50%; background-image: url(http://old.zdorovieinfo.ru/' + obj.root.Question._imageUrl + '); min-height: 570px; "></div>';
});
}
$('.resultTests').append(resultTests);
$('#flashMovie .getResultTests').addClass('substrateTest');
$('#question').html(obj.root.Question._textQuestion);
$('#questions').html(html);
jQuery('input[name="feeeeee"], input.inputValueAnswer').change(function (){
jQuery(this).attr('value', jQuery(this).val());
});
$('#questions .icheck').iCheck({
checkboxClass: 'iradio_minimal-blue  ',
radioClass: "iradio_minimal-blue ",
});
$('.resultTests input').iCheck('disable');
},
initButton: function (){
$('#buttonForMovie').html('   <button type="button" class="buttonArrow buttonArrowLeft firstButton" > ❮ </button>' +
'   <button type="button" class="buttonArrow buttonArrowRight lastButton"> Следующий вопрос</button>'
);
},
initTesting: function (){
if(jsonObj.root.configuration!==undefined){
prOprosID=jsonObj.root.configuration._prOprosID;
}
var data='idOpr=' + prOprosID + '&command=102&nomQuest=' + numQuest;
this.test('get', data);
},
initClick: function (){
var data='idOpr=' + prOprosID + '&command=103&nomQuest=' +(parseInt(jsonObj.root.Question._number));
$('.firstButton').on("click", function (){ classAjax.test('get', data); });
$('.lastButton').on("click", function (){
if($(this).hasClass('disabled')===false ||
($('#questions input[name=feeeeee][type="text"]').val()!==undefined &&
$('#questions input[name=feeeeee][type="text"]').val().length >=1) ||
(jQuery('#flashMovie select option:selected').val()!==undefined)
){ classAjax.test('get', classAjax.sendTest()); }});
$('#flashMovie select').select2();
$('.buttonArrow').click(function (){
if($('input[name=feeeeee]:checked').length===1 ||
($('#questions input[name=feeeeee][type="text"]').val()!==undefined &&
$('#questions input[name=feeeeee][type="text"]').val().length >=1) ||
(jQuery('#flashMovie select option:selected').val()!==undefined)
){
$('.buttonArrow').hide();
$('#buttonForMovie').html('<img class="loader"' +
' src="https://www.zdorovieinfo.ru/wp-content/uploads/2017/10/30.gif">');
}});
},
sendTest: function (){
var idQuestion=jsonObj.root.Question._questionID;
numQuest=parseInt(jsonObj.root.Question._number);
var xmlDoc='<root>' +
'<command id="102"/>' +
'<configuration ' +
' typeQuestion="' + jsonObj.root.Question._typeQuestion + '"' +
' typeWidget="' + jsonObj.root.Question._typeWidget + '" ' +
' numQuest="' + (numQuest) + '" prOprosID="' + prOprosID + '" idQuestion="' + idQuestion + '"/>' +
'<answers>';
var answers=jsonObj.root.Question.answers.Answer;
var answer;
var typeQuestiom='';
if(Array.isArray(answers)){
for(var i in answers){
answer=answers[i];
log("Answer", answer);
$('input[name=feeeeee]:checked').each(function (){
if(answer._pos===$(this).val()){
var typeAnswer=answer._type;
typeQuestiom='&answerType=' + answer._type +
'&type=' + answer._type;
xmlDoc +='<answer ImageSRC="' + answer._ImageSrc + '" ' +
'id="' + answer._answerID + '" ' +
'content_item_id="' + answer._answerID + '" ' +
'pos="' + answer._pos + '" ' +
'answerType="' + answer._type + '" ' +
'value="1" ' +
'text="' + answer.__text + '" ' +
'selected="true"/>';
}});
$('#flashMovie select option:selected').each(function (){
if(parseInt(answer._pos)===parseInt($(this).val())){
var typeAnswer=answer._type;
typeQuestiom='&answerType=' + answer._type +
'&type=' + answer._type;
xmlDoc +='<answer ImageSRC="' + answer._ImageSrc + '" ' +
'id="' + answer._answerID + '" ' +
'content_item_id="' + answer._answerID + '" ' +
'pos="' + answer._pos + '" ' +
'answerType="' + answer._type + '" ' +
'value="1" ' +
'text="' + answer.__text + '" ' +
'selected="true"/>';
}});
}}else{
answer=jsonObj.root.Question.answers.Answer;
log('text Answer: ', answer);
$('#flashMovie input[name="feeeeee"][type="text"]').each(function (){
var typeAnswer=answer._type;
typeQuestiom='&answerType=' + answer._type +
'&type=' + answer._type;
xmlDoc +='<answer ImageSRC="' + answer._ImageSrc + '" ' +
'id="' + answer._answerID + '" ' +
'content_item_id="' + answer._answerID + '" ' +
'answerType="' + answer._type + '" ' +
'value="' + jQuery(this).val() + '" ' +
'selected="true"/>';
});
}
xmlDoc +='</answers>' +
'</root>';
log('XMLDoc: ', xmlDoc);
return encodeURI('idOpr=' + prOprosID +
typeQuestiom +
'&command=102&nomQuest=' + (numQuest) + '&answers=' + xmlDoc);
},
test: function (type, data, callbeck){
var dataXml={},
get='',
post={};
if(type==='get'){
get="?" + data;
}else{ post=data; }
var sendUrl=this.urlAspx + (get.substr(0, get.indexOf("&answers=")));
$.post({
url: sendUrl,
data: data,
dataType: "text",
success: function (xml){
jsonObj=x2js.xml_str2json(xml);
var questenTitle='';
if($('.getResultTests').length!==0&&(parseInt(jsonObj.root.command._id)===103 ||
parseInt(jsonObj.root.command._id)===102)&&numQuest >=0){
sendGa();
numberQuestnToTitle++;
var titleQuesten='<div class="row "> ' +
'</div> ';
resultTests="<div class=\"questensData\">" + titleQuesten + $('.getResultTests').html().replace(/\sid=\"(.*?)\"/g, " ")
.replace(/\sfor=\"icheck(.*?)\"/g, "") + "</div>";
questenTitle='<h3 class="col-md-12"> Вопрос ' + numberQuestnToTitle + '.</h3>';
}
$('#flashMovie').html('' +
'' +
'           <div class="row contenerCont">' +
'               <div class="col-md-12 getResultTests noPadding">' +
questenTitle +
'                   <div class="row header-title"> ' +
'                       <h3 id="question" class="col-md-12"></h3><br/>' +
'                   </div> ' +
'                   <div class="row" >' +
'                      <div class="form-group" id="questions"></div>' +
'                   </div>' +
'               </div>' +
'               <div class="col-md-12" style="width: 100%">' +
'                   <div id="buttonForMovie" >' +
'                   </div>' +
'               </div>' +
'           </div>'
);
if((parseInt(jsonObj.root.command._id)===103 ||
parseInt(jsonObj.root.command._id)===102 ||
parseInt(jsonObj.root.command._id)===100) &&
(jsonObj.root.title!==undefined||parseInt(jsonObj.root.state._val)===0)){
$('.barPosition').show();
if(jsonObj.root.Image!==undefined&&jsonObj.root.Image._src!==undefined){
inserImageSrc=jsonObj.root.Image._src;
}
if(jsonObj.root.Question!==undefined&&jsonObj.root.Question._imageUrl!==undefined){
if(jsonObj.root.Question._imageUrl!=="" &&
jsonObj.root.Question._typeQuestion!="13536156")
inserImageSrc=jsonObj.root.Question._imageUrl;
$('#barPosition').html('<div class=" progress progress-sm active" style="width: 90%; display: inline-block;">' +
'           <div class="progress-bar progress-bar-custom progress-bar-striped" ' +
'role="progressbar" aria-valuenow="' + jsonObj.root.Question._percent +
'" aria-valuemin="0" aria-valuemax="100" ' +
'style="width: ' + jsonObj.root.Question._percent + '%">' +
'               ' +
'           </div>' +
'       </div>' +
'       <div style="display: inline;color: #fff;margin-left: 30px;"> ' +
jsonObj.root.Question._percent + '% выполнено' +
'</div>'
);
setTimeout(function (){
$('html, body').animate({
scrollTop: $("#flashMovie").offset().top - 100
}, 600);
}, 600);
classAjax.generatQuest(jsonObj);
classAjax.initButton();
classAjax.initClick();
}
$('#addImageTest').css("background-image", "url('http://old.zdorovieinfo.ru/" +
inserImageSrc + "')");
if(jsonObj.root.title!==undefined){
classAjax.initTest();
titleTest=jsonObj.root.title._text;
$('#questions').html(jsonObj.root.Description._text.replace(/\{quotes\}/g, '\''));
}}
if(jsonObj.root.Question!==undefined &&
parseInt(jsonObj.root.Question._questionID)===0){
var data='idOpr=' + prOprosID + '&command=104';
classAjax.test('get', data);
}
if(titleTest!==undefined){
$('#titleForTest').html(titleTest);
}
if(parseInt(jsonObj.root.command._id)===104){
sendEndGa();
numQuest=0;
var get="command=100&test=" + test;
classReplace.uploadText();
classReplace.uploadDecs();
$('.barPosition').hide();
$('#flashMovie').html('<img ' +
'src="https://www.zdorovieinfo.ru/wp-content/uploads/2017/10/25.gif" ' +
'style="text-align: center; ' +
'margin: 10px; position: absolute;right: 40%;top: 0;">');
setTimeout(function (){
$('.barPosition').hide();
jsonObj.root.textResult._text=jsonObj.root.textResult._text.replace(/\{quotes\}/g, '\'')
.replace(/<\/span>/g, '</span><br/>').replace(/src=\"\/upload\/contents\//g, 'src="http://old.zdorovieinfo.ru/upload/contents/');
jsonObj.root.description._text=jsonObj.root.description._text
.replace(/\{quotes\}/g, '\'').replace(/\]\]\>/g, '').replace(/\]\]\&gt\;/g, '')
.replace(/<\/span>/g, '</span><br/>').replace(/src=\"\/upload\/contents\//g, 'src="http://old.zdorovieinfo.ru/upload/contents/');
var resultTest='<div class="resultTest__wrap">' +
'<div id="resTest" style="padding: 10px;">' +
'<div  style="padding: 10px; ">' +
'    <div id="resultTest" >' +
'        ' + jsonObj.root.textResult._text.replace(/source/g, 'src').replace(/\{quotes\}/g, '\'')
.replace(/src=\"\/upload\/contents\//g, 'src="http://old.zdorovieinfo.ru/upload/contents/') +
'    </div>' +
'    <div id="descTest" >' +
'        ' + jsonObj.root.description._text.replace(/source/g, 'src')
.replace(/src=\"\/upload\/contents\//g, 'src="http://old.zdorovieinfo.ru/upload/contents/') +
'    </div>' +
'</div>' +
'</div>' +
'<div id="buttonForMovie" ' +
'style="padding-left: 15px; margin-right: 15px;">' +
'<button class="buttonArrow buttonBegin" onclick="classAjax.test(\'get\', get);"' +
'>Пройти тест ещё раз</button>' +
'</div></div>';
resultTests="";
numberQuestnToTitle=0;
$('#flashMovie').removeClass('addMainClass');
$('#flashMovie').css('background-color', 'white');
$('.resultTests').html('');
$('#flashMovie').html(resultTest);
}, 2500);
}},
error: function (xhr, ajaxOptions, thrownError){
log(xhr.status);
log(thrownError);
}});
}};
var classReplace={
migrationForStyle: {
"color": "color",
"fontfamily": "font-family",
"fontsize": "font-size",
"fontweight": "font-weight",
"paddingbottom": "padding-bottom",
"paddingleft": "padding-left",
"paddingright": "padding-right",
"paddingtop": "padding-top",
"height": "height",
"width": "width",
"source": "src",
"float": "float"
},
getCss: function (){
var css={};
var style={};
$(this).each(function (){
$.each(this.attributes, function (){
if(this.specified){
var option=classReplace.migrationForStyle[this.name.toLowerCase()]!==undefined ?
classReplace.migrationForStyle[this.name.toLowerCase()]:this.name;
style[option]=this.value;
if(classReplace.migrationForStyle[this.name]==='font-size'){
style[option] +='pt';
}}
});
});
$(this).css(style);
var attr=$(this).attr('style');
if(attr!==undefined){
var data=attr.split(';');
for (var i in data){
var explode=data[i].split(':');
if(explode[0]!==undefined&&explode[0]!==""){
css[explode[0].trim()]=explode[1].trim();
}}
}},
check: function (){
classReplace.getCss.call(this);
if($(this).children().length!==0){
$(this).children().each(function (index){
classReplace.getCss.call(this);
classReplace.check.call(this);
});
}else{
return true;
}},
uploadText: function (){
},
uploadDecs: function (){
},
};
function log(){
var dbgPlace=$('#DEBUG');
if(! dbgPlace.length){ return; }
$('<div>').append($('<strong>').html("Date:"),(new Date()).toJSON(), '<BR/>',
$('<strong>').html("Info: "), JSON.stringify(arguments), '<BR/>',
$('<strong>').html('Caller: '), JSON.stringify(arguments.callee), '<BR/><HR>')
.appendTo(dbgPlace);
return console.log.apply(null, arguments);
}
function findGetParameter(parameterName){
var result=null,
tmp=[];
location.search
.substr(1)
.split("&")
.forEach(function (item){
tmp=item.split("=");
if(tmp[0]===parameterName) result=decodeURIComponent(tmp[1]);
});
return result;
}
var test=window['shortcodeTest2-contentID'] ? window['shortcodeTest2-contentID']:6739501;
var get="command=100&test=" + test,
dataXml={},
titleTest,
jsonObj;
classAjax.test('get', get);
var addScrolling=true;
setInterval(function (){
$(parent.document).find('iframe').each(function (){
if($(this).attr('src')!==undefined&&$(this).attr('src').length > 1 &&
$(this).attr('src').indexOf('showflashtest')!==-1){
if(addScrolling){
$(this).attr('scrolling', "no");
addScrolling=false;
}
$(this).height(parseInt($('#flashMovie').height()) +
(2 * parseInt($('#flashMovie').css('padding').replace('px', ''))));
$(this).parent().height($(this).css('height'));
if($(this).css('width') + 15===$('#flashMovie').width()){
$(this).css('width', $('#flashMovie').width());
$(this).parent().css('width', $(this).css('width'));
}}
});
}, 1000);