function Multirepresentation(){}$(document).ready(function(){Multirepresentation.init()});Multirepresentation.init=function(){$('.hotspot').each(function(){if($(this).children('.meaning').html()!=null&&$(this).children('.meaning').html().length>0){$(this).qtip({content:$(this).children('.meaning').html(),show:{solo:true},hide:'unfocus'})}else{$(this).mouseover(function(){qTipManager.hideQtips()})}});$('.hotspotRectangle').mouseenter(function(){$(this).css('border','5px #ffcc00 solid');$(this).find('.dtitle').css('background-color','#ffcc00');$(this).fadeTo('normal',1)});$('.hotspotRectangle').mouseleave(function(){$(this).css('border','5px #F6F6F6 solid');$(this).find('.dtitle').css('background-color','#F6F6F6');$(this).fadeTo('normal',0.7)});$('.hotspotDot').mouseenter(function(){$(this).fadeTo('normal',1);$(this).addClass('highlightedHotspotDot')});$('.hotspotDot').mouseleave(function(){$(this).fadeTo('normal',0.7);$(this).removeClass('highlightedHotspotDot')});Multirepresentation.hotspotNumber=1;Multirepresentation.multirepresentationImageScaled=function(hotspot,scalingFactor){Multirepresentation.hotspotNumber++;$('.multirepresentationExercises').fadeIn('slow');if(scalingFactor!=1){$(hotspot).css('left',parseInt($(hotspot).css('left'),10)*scalingFactor);$(hotspot).css('top',parseInt($(hotspot).css('top'),10)*scalingFactor);if($(hotspot).hasClass('hotspotRectangle')){$(hotspot).css('width',parseInt($(hotspot).css('width'),10)*scalingFactor);$(hotspot).css('height',parseInt($(hotspot).css('height'),10)*scalingFactor)}}$(hotspot).attr('onmouseover','');$(hotspot).addClass('hotspot_'+Multirepresentation.hotspotNumber);if($(hotspot).hasClass('hotspotRectangle')){$(hotspot).css('display','block');$(hotspot).children('.dtitle').html(Multirepresentation.hotspotNumber);$(hotspot).mouseenter(function(){$('#multirepresentationQuestion_'+$(hotspot).children('.dtitle').html()).children().find('.maskinputfield').first().focus()})}else{$(hotspot).append('<div class="questionNumber">'+Multirepresentation.hotspotNumber+'</div>');$(hotspot).removeClass('hotspotDot');$(hotspot).addClass('hotspotDotFilled');$(hotspot).mouseenter(function(){$('#multirepresentationQuestion_'+$(hotspot).children('.questionNumber').html()).children().find('.maskinputfield').first().focus()})}$(hotspot).show();$(hotspot).fadeTo('slow',0.7)};$('.showMultirepresentationExercisesButton').click(function(){$('.navigationButtons').show();$('.showExercisesButton').hide();$('.multirepresentationhelp').hide();$('.repeatMultirepresentationLink').show();$('.multirepresentationdescription').hide();$('.hotspot').unbind('mouseenter');$('.hotspot').unbind('mouseleave');$('.hotspotDot').unbind('mouseenter');$('.hotspotDot').unbind('mouseleave');Multirepresentation.hotspotNumber=0;var currentImageWidth=$('#multirepresentationimageDisplay img.multirepresentationImage').eq(0).width();var targetImageWidth=520;var scalingFactor=1;if(currentImageWidth>targetImageWidth){scalingFactor=targetImageWidth/currentImageWidth}$('#multirepresentationimageDisplay').css('width',targetImageWidth);$('#multirepresentationimageDisplay .hotspot').fadeTo('slow',0,function(){var hotspot=this;$(hotspot).hide();$(this).qtip('disable');if(currentImageWidth>targetImageWidth){$('#multirepresentationimageDisplay img.multirepresentationImage').animate({width:targetImageWidth+'px'},function(){Multirepresentation.multirepresentationImageScaled(hotspot,scalingFactor)})}else{Multirepresentation.multirepresentationImageScaled(hotspot,scalingFactor)}})});if($(".draggableRectangle")){$(".draggableRectangle").draggable({containment:"#multirepresentationEditor",scroll:false,drag:function(event,ui){return Multirepresentation.updateHotspotsXml(this,ui)}}).resizable({containment:"#multirepresentationEditor",resize:function(event,ui){return Multirepresentation.updateHotspotsXml(this,ui)}})}if($(".draggableDot")){$(".draggableDot").draggable({containment:"#multirepresentationEditor",scroll:false,drag:function(event,ui){return Multirepresentation.updateHotspotsXml(this,ui)}})}$('#meaningSelector').click(function(){if($('#selectedDictionaryMeaningId')!=undefined){var selectedOption=Multirepresentation.getSelectedDictionaryMeaning();var dictionaryMeaningId='';if(selectedOption!=null){dictionaryMeaningId=selectedOption.data('dictionarymeaningid')}$('#selectedDictionaryMeaningId').val('dictionaryMeaningId="'+dictionaryMeaningId+'"')}});$('.maskinputfield').focus(function(){$('.multirepresentationQuestion').removeClass('highlightedMultirepresentationQuestion');$(this).parents('.multirepresentationQuestion').addClass('highlightedMultirepresentationQuestion');var hotspotNumber=$(this).parents('.multirepresentationQuestion').attr('id').split('_')[1];$('.hotspot').each(function(){if($(this).hasClass('hotspot_'+hotspotNumber)){if($(this).is('.hotspotDotFilled')){$(this).addClass('highlightedFilledHotspotDot')}else{$(this).addClass('highlightedHotspot')}$(this).css('opacity','1')}else{if($(this).is('.hotspotDotFilled')){$(this).removeClass('highlightedFilledHotspotDot')}else{$(this).removeClass('highlightedHotspot')}$(this).css('opacity','0.7')}})});$('#saveWithoutExam a').click(function(e){if(!ClozesFieldsManager.allExercisesCorrect()){alert('Aby przejść dalej, należy uzupełnić wszystkie brakujące podpisy.');e.preventDefault()}})};Multirepresentation.updateHotspotsXml=function(hotspot,ui){dictionarymeaningid=$(hotspot).data("dictionarymeaningid");text=$(hotspot).data("text");if((dictionarymeaningid!=undefined&&dictionarymeaningid!='')||(text!=undefined&&text!='')){hotspotsXML=$.parseXML('<hotspots>'+$("#hotspoty_xml").val()+'</hotspots>');var resultXml='';hotspots=$(hotspotsXML).find('hotspot');for(var i=0;i<hotspots.length;i++){if($(hotspots[i]).attr('text')==text){resultXml+=("<hotspot left=\""+ui.position.left+"\" top=\""+ui.position.top+"\" width=\""+Math.round($(hotspot).width())+"\" height=\""+Math.round($(hotspot).height()+10)+"\" text=\""+$(hotspot).find(".dtitle").text()+"\" dictionaryMeaningId=\""+$(hotspot).data("dictionarymeaningid")+"\" />\n")}else{resultXml+=("<hotspot left=\""+$(hotspots[i]).attr('left')+"\" top=\""+$(hotspots[i]).attr('top')+"\" width=\""+$(hotspots[i]).attr('width')+"\" height=\""+$(hotspots[i]).attr('height')+"\" text=\""+$(hotspots[i]).attr('text')+"\" dictionaryMeaningId=\""+$(hotspots[i]).attr('dictionaryMeaningId')+"\" />\n")}}hotspots=$(hotspotsXML).find('dot');for(i=0;i<hotspots.length;i++){if($(hotspots[i]).attr('text')==text){resultXml+=("<dot left=\""+ui.position.left+"\" top=\""+ui.position.top+"\" text=\""+$(hotspot).data("text")+"\" dictionaryMeaningId=\""+$(hotspot).data("dictionarymeaningid")+"\" />\n")}else{resultXml+=("<dot left=\""+$(hotspots[i]).attr('left')+"\" top=\""+$(hotspots[i]).attr('top')+"\" text=\""+$(hotspots[i]).attr('text')+"\" dictionaryMeaningId=\""+$(hotspots[i]).attr('dictionaryMeaningId')+"\" />\n")}}$("#hotspoty_xml").val(resultXml)}else{$('#dictionaryMeaning').val(text);$('#dictionaryMeaning').change();var selectedOption=Multirepresentation.getSelectedDictionaryMeaning();var dictionaryMeaningId='';if(selectedOption!=null){dictionaryMeaningId=selectedOption.data('dictionarymeaningid');$('#selectedDictionaryMeaningId').val('dictionaryMeaningId="'+dictionaryMeaningId+'"')}else{alert('Dodaj tytuł (atrybut text) elementu, aby móc go edytować.');return false}}return true};Multirepresentation.getSelectedDictionaryMeaning=function(){var selectedOption=null;$('#meaningSelector option').each(function(){if($(this).is(':selected')){selectedOption=$(this)}});return selectedOption};Multirepresentation.hotspotExists=function(dictionaryMeaningId){hotspotsXML=$.parseXML('<hotspots>'+$("#hotspoty_xml").val()+'</hotspots>');hotspots=$(hotspotsXML).find('hotspot');for(var i=0;i<hotspots.length;i++){if($(hotspots[i]).attr('dictionaryMeaningId')==dictionaryMeaningId){return true}}hotspots=$(hotspotsXML).find('dot');for(i=0;i<hotspots.length;i++){if($(hotspots[i]).attr('dictionaryMeaningId')==dictionaryMeaningId){return true}}return false};Multirepresentation.addHotspot=function(type){var selectedOption=Multirepresentation.getSelectedDictionaryMeaning();var dictionaryMeaningId='';var title='';if(selectedOption!=null){dictionaryMeaningId=selectedOption.data('dictionarymeaningid');title=selectedOption.data('foreignword')}if(Multirepresentation.hotspotExists(dictionaryMeaningId)){alert('Wybrane słowo istnieje już jako hotspot. Wybierz inne.')}else{var elementXml='';if(type=='rectangle'){elementXml='<hotspot left="129" top="25" width="110" height="90" text="'+title+'" dictionaryMeaningId="'+dictionaryMeaningId+'" />'}else{elementXml='<dot left="129" top="25" text="'+title+'" dictionaryMeaningId="'+dictionaryMeaningId+'" />'}$('#hotspoty_xml').val($('#hotspoty_xml').val()+'\n'+elementXml);Multirepresentation.updateMultirepresentationPreview()}};Multirepresentation.updateMultirepresentationPreview=function(){$.post('/adminpanel/multireprezentacja/ajaxMultirepresentationPreview.php',{'id':$('#multirepresentationElementId').val(),'hotspotsXml':$('#hotspoty_xml').val()},function(result){$('#multirepresentationEditor').html(result);Multirepresentation.init()})};

