From a7b4fc23757e7f47f4a8285263526abf32cb0197 Mon Sep 17 00:00:00 2001 From: Franzz Date: Mon, 30 Aug 2021 23:23:57 +0200 Subject: [PATCH] Add project local functions to main spot class --- script/lightbox.js | 12 +++++++++--- script/spot.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/script/lightbox.js b/script/lightbox.js index 8a4493c..d1218ea 100644 --- a/script/lightbox.js +++ b/script/lightbox.js @@ -372,7 +372,7 @@ return {maxWidth: iMaxMediaWidth, maxHeight: iMaxMediaHeight, direction: sDirection}; }; - updateHash('media', self.album[imageNumber].id); + oSpot.updateHash('media', self.album[imageNumber].id); if(self.options.hasVideo) { var $lbContainer = this.$lightbox.find('.lb-container'); @@ -585,7 +585,10 @@ self.$lightbox.find('.lb-nextLink').height(newHeight); // Set focus on one of the two root nodes so keyboard events are captured. - self.$overlay.focus(); + //ADDED-START + //self.$overlay.focus(); + self.$overlay.trigger( 'focus' ); + //ADDED-END self.showImage(); } @@ -704,6 +707,9 @@ }; Lightbox.prototype.enableKeyboardNav = function() { + //ADDED-START + this.disableKeyboardNav(); + //ADDED-END this.$lightbox.on('keyup.keyboard', $.proxy(this.keyboardAction, this)); this.$overlay.on('keyup.keyboard', $.proxy(this.keyboardAction, this)); }; @@ -750,7 +756,7 @@ if($hasVideoNav) $lbContainer.removeClass('lb-video-nav'); } - flushHash(); + oSpot.flushHash(); //ADDED-END $(window).off('resize', this.sizeOverlay); diff --git a/script/spot.js b/script/spot.js index d87e309..4d2860a 100755 --- a/script/spot.js +++ b/script/spot.js @@ -149,6 +149,20 @@ function Spot(asGlobals) if(bReboot) location.reload(); }; + this.updateHash = function(sType, iId) { + sType = sType || ''; + iId = iId || 0; + + var asHash = self.getHash(); + if(iId) self.setHash(asHash.page, [asHash.items[0], sType, iId]); + }; + + this.flushHash = function(asTypes) { + asTypes = asTypes || []; + var asHash = self.getHash(); + if(asHash.items.length > 1 && (asTypes.length == 0 || asTypes.indexOf(asHash.items[1]) != -1)) self.setHash(asHash.page, [asHash.items[0]]); + }; + /* Page Switch - DOM Replacement */ this.getActionLink = function(sAction, oVars) @@ -227,6 +241,23 @@ function Spot(asGlobals) var $FadeInElem = bFirstPage?self.elem.container:self.elem.main; $FadeInElem.hide().fadeTo('slow', 1); }; + + this.getNaturalDuration = function(iHours) { + var iTimeMinutes = 0, iTimeHours = 0, iTimeDays = Math.floor(iHours/8); //8 hours a day + if(iTimeDays > 1) iTimeDays = Math.round(iTimeDays * 2) / 2; //Round down to the closest half day + else { + iTimeDays = 0; + iTimeHours = Math.floor(iHours); + iHours -= iTimeHours; + + iTimeMinutes = Math.floor(iHours * 4) * 15; //Round down to the closest 15 minutes + } + return '~ ' + +(iTimeDays>0?(iTimeDays+(iTimeDays%2==0?'':'½')+' '+oSpot.lang(iTimeDays>1?'unit_days':'unit_day')):'')//Days + +((iTimeHours>0 || iTimeDays==0)?iTimeHours+oSpot.lang('unit_hour'):'') //Hours + +((iTimeDays>0 || iTimeMinutes==0)?'':iTimeMinutes) //Minutes + + }; } /* Common Functions */