Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Version to 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kos committed Sep 18, 2015
1 parent 270bd9a commit 2f52ba6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bulbs-public-embed-instagram",
"version": "0.0.6",
"version": "0.0.7",
"main": [
"dist/jquery.instagram-embed-processor.js"
],
Expand Down
37 changes: 23 additions & 14 deletions dist/jquery.instagram-embed-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
};
Expand All @@ -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();
}
Expand Down

0 comments on commit 2f52ba6

Please sign in to comment.