Skip to content

Commit

Permalink
DOWN-440: Update javascript for agreement page handling
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Jun 29, 2023
1 parent 28ac5b8 commit 798df14
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
21 changes: 17 additions & 4 deletions src/media/js/jquery.osdownloads.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
animation = $this.data('animation'),
popupElementId = prefix + '_popup',
$popup = $('#' + popupElementId),
$btnContinue = $popup.find('.osdownloads-continue-button'),
$form = $popup.find('form');
$btnContinue = $('.osdownloads-continue-button', $popup),
$form = $('form', $popup);

if ($popup.length !== 1 && $form.length !== 1) {
return;
Expand Down Expand Up @@ -89,9 +89,22 @@
event.preventDefault();
event.stopPropagation();

$btnContinue.prop('href', $this.prop('href'));

if ($btnContinue.length && $form[0].elements.length) {
let $agreeGroup = $('.osdownloads-group-agree', $popup),
agreeLink = $this.data('agreement-article');

if ($agreeGroup.length) {
if (agreeLink) {
$agreeGroup.show();
$('a.agreement-article', $agreeGroup).prop('href', agreeLink);

} else {
$agreeGroup.hide();
}
}

$btnContinue.prop('href', $this.data('agreement-article'));

showPopup('#' + popupElementId);

$popup.on(
Expand Down
5 changes: 3 additions & 2 deletions src/media/js/jquery.osdownloads.bundle.min.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;jQuery(function($){$.fn.osdownloads=function osdownloads(options){if(this.length){return this.each(function(){if($(this).data('osdownloads-loaded')===1){return;}
let $this=$(this),prefix=$this.data('prefix'),animation=$this.data('animation'),popupElementId=prefix+'_popup',$popup=$('#'+popupElementId),$btnContinue=$popup.find('.osdownloads-continue-button'),$form=$popup.find('form');if($popup.length!==1&&$form.length!==1){return;}
$popup.appendTo($('body'));let $validator=$form.validate();let showPopup=function(selector){$(selector).reveal({animation:animation,animationspeed:200,closeonbackgroundclick:true,dismissmodalclass:'close-reveal-modal',});};let download=function(){$form.prop('target','osdownloads-tmp-iframe-'+$form.prop('id'));$container=$('<div>').prop('id',prefix+'PopupIframe').addClass('reveal-modal').addClass('osdownloads-modal');$iframe=$('<iframe>').prop('name','osdownloads-tmp-iframe-'+$form.prop('id'));$close=$('<a class="close-reveal-modal">&#215;</a>');$iframe.appendTo($container);$close.appendTo($container);$container.appendTo($('body'));$form.submit();$container.on('reveal:close',function(){setTimeout(function(){$container.remove();},500);});$popup.trigger('reveal:close');setTimeout(function(){showPopup('#'+prefix+'PopupIframe');},500);};$this.on('click',function(event){event.preventDefault();event.stopPropagation();$btnContinue.prop('href',$this.prop('href'));if($btnContinue.length&&$form[0].elements.length){showPopup('#'+popupElementId);$popup.on('reveal:close',function(){setTimeout(function(){$form[0].reset();$validator.resetForm();},500);});$btnContinue.off();$btnContinue.on('click',function(event){event.preventDefault();if($form.valid()){download();}});}else{download();}});$this.data('osdownloads-loaded',1);});}};});(function($){$('a[data-reveal-id]').on('click',function(event){event.preventDefault();var modalLocation=$(this).attr('data-reveal-id');$('#'+modalLocation).reveal($(this).data());});$.fn.reveal=function(options){var defaults={animation:'fadeAndPop',animationSpeed:300,closeOnBackgroundClick:true,dismissModalClass:'close-reveal-modal'};var options=$.extend({},defaults,options);return this.each(function(){var modal=$(this),topMeasure=parseInt(modal.css('top')),topOffset=modal.height()+topMeasure,locked=false,modalBg=$('.reveal-modal-bg');if(modalBg.length==0){modalBg=$('<div class="reveal-modal-bg" />').insertAfter(modal);modalBg.fadeTo('fast',0.8);}
let $this=$(this),prefix=$this.data('prefix'),animation=$this.data('animation'),popupElementId=prefix+'_popup',$popup=$('#'+popupElementId),$btnContinue=$('.osdownloads-continue-button',$popup),$form=$('form',$popup);if($popup.length!==1&&$form.length!==1){return;}
$popup.appendTo($('body'));let $validator=$form.validate();let showPopup=function(selector){$(selector).reveal({animation:animation,animationspeed:200,closeonbackgroundclick:true,dismissmodalclass:'close-reveal-modal',});};let download=function(){$form.prop('target','osdownloads-tmp-iframe-'+$form.prop('id'));$container=$('<div>').prop('id',prefix+'PopupIframe').addClass('reveal-modal').addClass('osdownloads-modal');$iframe=$('<iframe>').prop('name','osdownloads-tmp-iframe-'+$form.prop('id'));$close=$('<a class="close-reveal-modal">&#215;</a>');$iframe.appendTo($container);$close.appendTo($container);$container.appendTo($('body'));$form.submit();$container.on('reveal:close',function(){setTimeout(function(){$container.remove();},500);});$popup.trigger('reveal:close');setTimeout(function(){showPopup('#'+prefix+'PopupIframe');},500);};$this.on('click',function(event){event.preventDefault();event.stopPropagation();if($btnContinue.length&&$form[0].elements.length){let $agreeGroup=$('.osdownloads-group-agree',$popup),agreeLink=$this.data('agreement-article');if($agreeGroup.length){if(agreeLink){$agreeGroup.show();$('a.agreement-article',$agreeGroup).prop('href',agreeLink);}else{$agreeGroup.hide();}}
$btnContinue.prop('href',$this.data('agreement-article'));showPopup('#'+popupElementId);$popup.on('reveal:close',function(){setTimeout(function(){$form[0].reset();$validator.resetForm();},500);});$btnContinue.off();$btnContinue.on('click',function(event){event.preventDefault();if($form.valid()){download();}});}else{download();}});$this.data('osdownloads-loaded',1);});}};});(function($){$('a[data-reveal-id]').on('click',function(event){event.preventDefault();var modalLocation=$(this).attr('data-reveal-id');$('#'+modalLocation).reveal($(this).data());});$.fn.reveal=function(options){var defaults={animation:'fadeAndPop',animationSpeed:300,closeOnBackgroundClick:true,dismissModalClass:'close-reveal-modal'};var options=$.extend({},defaults,options);return this.each(function(){var modal=$(this),topMeasure=parseInt(modal.css('top')),topOffset=modal.height()+topMeasure,locked=false,modalBg=$('.reveal-modal-bg');if(modalBg.length==0){modalBg=$('<div class="reveal-modal-bg" />').insertAfter(modal);modalBg.fadeTo('fast',0.8);}
function openAnimation(){modalBg.unbind('click.modalEvent');$('.'+options.dismissModalClass).unbind('click.modalEvent');if(!locked){lockModal();if(options.animation=="fadeAndPop"){modal.css({'top':$(document).scrollTop()-topOffset,'opacity':0,'visibility':'visible'});modalBg.fadeIn(options.animationSpeed / 2);modal.delay(options.animationSpeed / 2).animate({"top":$(document).scrollTop()+topMeasure+'px',"opacity":1},options.animationSpeed,unlockModal);}
if(options.animation=="fade"){modal.css({'opacity':0,'visibility':'visible','top':$(document).scrollTop()+topMeasure});modalBg.fadeIn(options.animationSpeed / 2);modal.delay(options.animationSpeed / 2).animate({"opacity":1},options.animationSpeed,unlockModal);}
if(options.animation=="none"){modal.css({'visibility':'visible','top':$(document).scrollTop()+topMeasure});modalBg.css({"display":"block"});unlockModal();}}
Expand Down
21 changes: 17 additions & 4 deletions src/media/js/jquery.osdownloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
animation = $this.data('animation'),
popupElementId = prefix + '_popup',
$popup = $('#' + popupElementId),
$btnContinue = $popup.find('.osdownloads-continue-button'),
$form = $popup.find('form');
$btnContinue = $('.osdownloads-continue-button', $popup),
$form = $('form', $popup);

if ($popup.length !== 1 && $form.length !== 1) {
return;
Expand Down Expand Up @@ -89,9 +89,22 @@
event.preventDefault();
event.stopPropagation();

$btnContinue.prop('href', $this.prop('href'));

if ($btnContinue.length && $form[0].elements.length) {
let $agreeGroup = $('.osdownloads-group-agree', $popup),
agreeLink = $this.data('agreement-article');

if ($agreeGroup.length) {
if (agreeLink) {
$agreeGroup.show();
$('a.agreement-article', $agreeGroup).prop('href', agreeLink);

} else {
$agreeGroup.hide();
}
}

$btnContinue.prop('href', $this.data('agreement-article'));

showPopup('#' + popupElementId);

$popup.on(
Expand Down

0 comments on commit 798df14

Please sign in to comment.