UNPKG

imageviewer_terrydr

Version:

A simple jQuery image viewing plugin.

59 lines (48 loc) 1.34 kB
Viewer.prototype = { constructor: Viewer, init: function () { var options = this.options; var $this = this.$element; var isImg = $this.is(SELECTOR_IMG); var $images = isImg ? $this : $this.find(SELECTOR_IMG); var length = $images.length; var ready = $.proxy(this.ready, this); if (!length) { return; } if ($.isFunction(options.build)) { $this.one(EVENT_BUILD, options.build); } if (this.trigger(EVENT_BUILD).isDefaultPrevented()) { return; } // Override `transition` option if it is not supported if (!SUPPORT_TRANSITION) { options.transition = false; } this.isImg = isImg; this.length = length; this.count = 0; this.$images = $images; this.$body = $('body'); if (options.inline) { $this.one(EVENT_BUILT, $.proxy(function () { this.view(); }, this)); $images.each(function () { if (this.complete) { ready(); } else { $(this).one(EVENT_LOAD, ready); } }); } else { $this.on(EVENT_CLICK, $.proxy(this.start, this)); } }, ready: function () { this.count++; if (this.count === this.length) { this.build(); } },