Обновить скрипт
Здавствуйте, обновил jquery со 2 версии на 3, и похоже что один скрипт не заточен под новую версию, как можно обновить его? Помогите плиз
/*! simplezoom 09-06-2015 */ (function($) { var defaults = { classie: '', offset: 40, scrollclose: true, imgclass: 'img', duration: 0, modalTmpl: null, loaderTmpl: null }; var TEMPLATE = '<div class="modal-simplezoom modal">' + '<div class="modal-bg"></div>' + '<div class="modal-content">' + '<div class="simplezoom-item">' + '<img src="{{img}}" alt="simplezoom-img" />' + '</div>' + '</div>' + '</div>'; var LOADER = '<div class="simplezoom-loader loader"><i></i></div>'; function SimpleZoom(el, options) { this.$el = $(el); this.options = $.extend(true, {}, defaults, options, this.$el.data()); this.$img = this.$el.find(this.options.imgclass); if (this.$img.length === 0) return; this.$img = this.$img.first(); this.img_lg = this.$el.attr('href'); this.img_sm = this.$img.attr('src'); if (!this.img_lg || !this.img_sm || this.img_lg == '#') return; var self = this; this.$el.on('click.simplezoom', function(e) { e.preventDefault(); self.showModal() }) } $.extend(SimpleZoom.prototype, { showModal: function() { var self = this, timer = null; this.$modal = this.createModal(this.img_sm); this.$content = this.$modal.find('.simplezoom-item'); this.setInitPosition(); if (this.options.duration) this.$content.css('transitionDuration', this.options.duration + 'ms'); this.$img.css('visibility', 'hidden'); this.loadImageMeta(this.img_sm, function(meta) { if (!self.$modal || self.isClosing) return; self.setFullPosition(meta); self.$content.append(self.options.loaderTmpl || LOADER); self.$modal.addClass('in loading'); self.loadImageMeta(self.img_lg, function(meta) { if (!self.$modal || self.isClosing) return; self.$modal.removeClass('loading'); if (!meta) return; self.$content.find('img').attr('src', self.img_lg); self.setFullPosition(meta); self.evtTrigger('onImageLoaded') }); $(window).on('resize.simplezoom', function(e) { clearTimeout(timer); timer = setTimeout(function() { self.setFullPosition(meta) }, 100) }); self.$modal.on('click', function(e) { self.closeModal() }); if (self.options.scrollclose) { $(window).on('scroll.simplezoom', function(e) { self.closeModal() }) } }); self.evtTrigger('onModalInit') }, closeModal: function() { var self = this; this.isClosing = true; this.$modal.removeClass('in'); this.$content.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function() { if (self.$modal != null) { self.$modal.remove() }; self.$modal = null; self.$img.css('visibility', 'visible'); $(window).off('resize.simplezoom').off('scroll.simplezoom'); self.isClosing = false }); this.setInitPosition(); this.evtTrigger('onModalClosed') }, createModal: function(img) { var html = this.options.modalTmpl || TEMPLATE; html = html.replace('{{img}}', img); return $(html).addClass(this.options.classie).appendTo('body') }, setInitPosition: function() { var initCSS = { width: this.$img.width(), height: this.$img.height(), left: this.$img.offset().left, top: this.$img.offset().top - $(window).scrollTop() }; this.$content.css(initCSS) }, setFullPosition: function(meta) { var i_width, i_height, w_width, w_height, i_ratio, w_ratio, offsetX, offsetY; i_width = meta.w; i_height = meta.h; i_ratio = i_width / i_height; w_width = $(window).width() - this.options.offset * 2; w_height = $(window).height() - this.options.offset * 2; w_ratio = w_width / w_height; if (w_ratio > i_ratio) { i_height = Math.min(w_height, i_height); i_width = i_height * i_ratio } else { i_width = Math.min(w_width, i_width); i_height = i_width / i_ratio } offsetX = ($(window).width() - i_width) / 2; offsetY = ($(window).height() - i_height) / 2; this.$content.css({ width: i_width, height: i_height, left: offsetX, top: offsetY }) }, loadImageMeta: function(url, callback) { var self = this; $('<img />').load(function() { callback({ w: this.width, h: this.height }) }).error(function() { self.evtTrigger('onImageError'); callback(null) }).attr('src', url) }, evtTrigger: function(name) { if (!name || !this.options[name] || (typeof this.options[name] != 'function')) return; this.options[name].call(this, this.$el, this.$modal) } }); $.fn.simplezoom = function(options) { var attribute = 'iws_simplezoom'; return this.each(function() { var instance = $.data(this, attribute); if (!instance) { instance = new SimpleZoom(this, options); $.data(this, attribute, instance) } }) } })(jQuery); |
Perepelenok,
строки 125 и 130 переписать через on и в строку 72 добавить условие что this.$modal есть. |
Часовой пояс GMT +3, время: 13:56. |