From 2f52ba69b3758d35e4fcafca9c76fe903a48fd51 Mon Sep 17 00:00:00 2001 From: Andrew Kos Date: Thu, 17 Sep 2015 21:59:04 -0500 Subject: [PATCH] Version to 0.0.7 --- bower.json | 2 +- dist/jquery.instagram-embed-processor.js | 37 +++++++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/bower.json b/bower.json index a1c929e..ddde06d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bulbs-public-embed-instagram", - "version": "0.0.6", + "version": "0.0.7", "main": [ "dist/jquery.instagram-embed-processor.js" ], diff --git a/dist/jquery.instagram-embed-processor.js b/dist/jquery.instagram-embed-processor.js index 88c8af2..d784479 100644 --- a/dist/jquery.instagram-embed-processor.js +++ b/dist/jquery.instagram-embed-processor.js @@ -5,15 +5,17 @@ var InstagramEmbedProcessor = function ($element, options) { }, options); this.$container = $element; this.$container.data('pluginInstagramEmbedProcessor', this); + + this.$container.attr('instagram-processor-version', this._getVersion()); }; -// store deferred for getting instagram object -InstagramEmbedProcessor.prototype.shared = {instagramLoaded: null}; +// store deferred for getting instagram object, use same deferred accross all instances +InstagramEmbedProcessor.prototype._shared = {instagramLoaded: null}; InstagramEmbedProcessor.prototype._getInstagramEmbedScript = function () { - if (!this.shared.instagramLoaded || this.shared.instagramLoaded.state() === 'rejected') { + if (!this._shared.instagramLoaded || this._shared.instagramLoaded.state() === 'rejected') { - this.shared.instagramLoaded = $.Deferred(); + this._shared.instagramLoaded = $.Deferred(); var self = this; $.getScript(this._settings.instagramEmbedScriptUrl) @@ -26,17 +28,25 @@ InstagramEmbedProcessor.prototype._getInstagramEmbedScript = function () { }); } - return this.shared.instagramLoaded.promise(); + return this._shared.instagramLoaded.promise(); }; -InstagramEmbedProcessor.prototype.sanitizeHtml = function (html) { +InstagramEmbedProcessor.prototype._sanitizeHtml = function (html) { return $(html).not('script').prop('outerHTML'); }; -InstagramEmbedProcessor.prototype.getVersion = function () { +InstagramEmbedProcessor.prototype._getVersion = function () { return '1.0.0'; }; +InstagramEmbedProcessor.prototype.html = function (unescapedHtml) { + if (typeof(unescapedHtml) === 'string') { + this.$container.attr('instagram-embed-html', escape(unescapedHtml)); + } + + return unescape(this.$container.attr('instagram-embed-html')); +}; + InstagramEmbedProcessor.prototype.isRendered = function (val) { return this.$container.data('instagramEmbedRendered') === true; }; @@ -50,22 +60,21 @@ InstagramEmbedProcessor.prototype.prep = function (embedHtml) { html = embedHtml; } - var sanitized = this.sanitizeHtml(html); - this.$container.attr('instagram-processor-version', this.getVersion()); - this.$container.attr('instagram-embed-html', escape(sanitized)); + var sanitized = this._sanitizeHtml(html); + this.html(sanitized); }; InstagramEmbedProcessor.prototype.render = function () { var rendered; if (!this.isRendered()) { + var self = this; rendered = this._getInstagramEmbedScript().done(function () { - var code = this.attr('instagram-embed-html'); - this.html(unescape(code)); + self.$container.html(self.html()); instgrm.Embeds.process(); - this.data('instagramEmbedRendered', true); - }.bind(this.$container)); + self.$container.data('instagramEmbedRendered', true); + }); } else { rendered = this._getInstagramEmbedScript(); }