').css(styles.wrap).appendTo(this.$container); // Non-body elements need some style adjustments if (!this.isBody) { // If the container is statically positioned, we need to make it relative, // and if no zIndex is defined, we should set it to zero. var position = this.$container.css('position') , zIndex = this.$container.css('zIndex'); this.$container.css({ position: position === 'static' ? 'relative' : position , zIndex: zIndex === 'auto' ? 0 : zIndex , background: 'none' }); // Needs a higher z-index this.$wrap.css({zIndex: -999998}); } // Fixed or absolute positioning? this.$wrap.css({ position: this.isBody && supportsFixedPosition ? 'fixed' : 'absolute' }); // Set the first image this.index = 0; this.show(this.index); // Listen for resize $(window).on('resize.backstretch', $.proxy(this.resize, this)) .on('orientationchange.backstretch', $.proxy(function () { // Need to do this in order to get the right window height if (this.isBody && window.pageYOffset === 0) { window.scrollTo(0, 1); this.resize(); } }, this)); }; /* PUBLIC METHODS * ========================= */ Backstretch.prototype = { resize: function () { try { var bgCSS = {left: 0, top: 0} , rootWidth = this.isBody ? this.$root.width() : this.$root.innerWidth() , bgWidth = rootWidth , rootHeight = this.isBody ? ( window.innerHeight ? window.innerHeight : this.$root.height() ) : this.$root.innerHeight() , bgHeight = bgWidth / this.$img.data('ratio') , bgOffset; // Make adjustments based on image ratio /* if (bgHeight >= rootHeight) { bgOffset = (bgHeight - rootHeight) / 2; if(this.options.centeredY) { bgCSS.top = '-' + bgOffset + 'px'; } } else { bgHeight = rootHeight; bgWidth = bgHeight * this.$img.data('ratio'); bgOffset = (bgWidth - rootWidth) / 2; if(this.options.centeredX) { bgCSS.left = '-' + bgOffset + 'px'; } } */ this.$container.css({height: bgHeight}); // added by IUCr this.$wrap.css({width: rootWidth, height: bgHeight}) .find('img:not(.deleteable)').css({width: bgWidth, height: bgHeight}).css(bgCSS); } catch(err) { // IE7 seems to trigger resize before the image is loaded. // This try/catch block is a hack to let it fail gracefully. } return this; } // Show the slide at a certain position , show: function (newIndex) { // Validate index if (Math.abs(newIndex) > this.images.length - 1) { return; } // Vars var self = this , oldImage = self.$wrap.find('img').addClass('deleteable') , oldLink = self.$wrap.find('a').addClass('deleteable') // added by IUCr , evtOptions = { relatedTarget: self.$container[0] }; // Trigger the "before" event self.$container.trigger($.Event('backstretch.before', evtOptions), [self, newIndex]); // Set the new index this.index = newIndex; // Pause the slideshow clearInterval(self.interval); // New image self.$img = $('') .css(styles.img) .bind('load', function (e) { var imgWidth = this.width || $(e.target).width() , imgHeight = this.height || $(e.target).height(); // Save the ratio $(this).data('ratio', imgWidth / imgHeight); // Show the image, then delete the old one // "speed" option has been deprecated, but we want backwards compatibilty $(this).fadeIn(self.options.speed || self.options.fade, function () { oldImage.remove(); oldLink.remove(); // added by IUCr // Resume the slideshow if (!self.paused) { self.cycle(); } // Trigger the "after" and "show" events // "show" is being deprecated $(['after', 'show']).each(function () { self.$container.trigger($.Event('backstretch.' + this, evtOptions), [self, newIndex]); }); }); // Resize self.resize(); }) .appendTo(self.$wrap); // Hack for IE img onload event self.$img.attr('src', self.images[newIndex]); self.$img.wrap($("").attr("href", IUCr_links[newIndex])) return self; } , next: function () { // Next slide return this.show(this.index 1) { // Clear the interval, just in case clearInterval(this.interval); this.interval = setInterval($.proxy(function () { // Check for paused slideshow if (!this.paused) { this.next(); } }, this), this.options.duration); } return this; } , destroy: function (preserveBackground) { // Stop the resize events $(window).off('resize.backstretch orientationchange.backstretch'); // Clear the interval clearInterval(this.interval); // Remove Backstretch if(!preserveBackground) { this.$wrap.remove(); } this.$container.removeData('backstretch'); } }; /* SUPPORTS FIXED POSITION? * * Based on code from jQuery Mobile 1.1.0 * https://jquerymobile.com/ * * In a nutshell, we need to figure out if fixed positioning is supported. * Unfortunately, this is very difficult to do on iOS, and usually involves * injecting content, scrolling the page, etc.. It's ugly. * jQuery Mobile uses this workaround. It's not ideal, but works. * * Modified to detect IE6 * ========================= */ var supportsFixedPosition = (function () { var ua = navigator.userAgent , platform = navigator.platform // Rendering engine is Webkit, and capture major version , wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ ) , wkversion = !!wkmatch && wkmatch[ 1 ] , ffmatch = ua.match( /Fennec\/([0-9]+)/ ) , ffversion = !!ffmatch && ffmatch[ 1 ] , operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ ) , omversion = !!operammobilematch && operammobilematch[ 1 ] , iematch = ua.match( /MSIE ([0-9]+)/ ) , ieversion = !!iematch && iematch[ 1 ]; return !( // iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5) ((platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion -1 && wkversion && wkversion -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1) || // IE6 (ieversion && ieversion

IUCr Congress collection


Celebrating the 75th Anniversary of the IUCr

Articles from IUCr Journals

latest articles
loading
most read
loading
most cited
loading
highlighted articles
loading
loading
loading
loading
loading
Follow IUCr Journals
Sign up for e-alerts
Follow IUCr on Twitter
Follow us on facebook
Sign up for RSS feeds