Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from e111077/check-attached
Browse files Browse the repository at this point in the history
checks if attached before ready
  • Loading branch information
e111077 authored Nov 2, 2016
2 parents a57e5ec + d15058d commit 158146d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
3 changes: 3 additions & 0 deletions twitter-timeline.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class twitterTimeline {
ready () {
this._computeLibLink()
this._computeUniqueId()
if (this.$.loaderTwtt.isAttached) {
this.$.loaderTwtt.attached();
}
}

/**
Expand Down
89 changes: 47 additions & 42 deletions twitter-timeline.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
'use strict'
'use strict';

var _createClass = function () { function defineProperties (target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }()
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function') } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Polymer = window.Polymer
var CustomEvent = window.CustomEvent
var Polymer = window.Polymer;
var CustomEvent = window.CustomEvent;

var twitterTimeline = function () {
function twitterTimeline () {
_classCallCheck(this, twitterTimeline)
function twitterTimeline() {
_classCallCheck(this, twitterTimeline);
}

_createClass(twitterTimeline, [{
key: 'beforeRegister',


// Element setup goes in beforeRegister instead of createdCallback.
value: function beforeRegister () {
this.is = 'twitter-timeline'
value: function beforeRegister() {
this.is = 'twitter-timeline';

// Define the properties object in beforeRegister.
this.properties = {
Expand Down Expand Up @@ -46,23 +47,26 @@ var twitterTimeline = function () {
*/
size: {
type: Object,
value: function value () {
value: function value() {
return {
width: '400',
height: '400'
}
};
}
}
}
};
}

// onReady fill <lib-loader> component to load Ace.js from CDN

}, {
key: 'ready',
value: function ready () {
this._computeLibLink()
this._computeUniqueId()
value: function ready() {
this._computeLibLink();
this._computeUniqueId();
if (this.$.loaderTwtt.isAttached) {
this.$.loaderTwtt.attached();
}
}

/**
Expand All @@ -72,13 +76,13 @@ var twitterTimeline = function () {

}, {
key: 'loadTimeline',
value: function loadTimeline (widgetId) {
var _this = this
value: function loadTimeline(widgetId) {
var _this = this;

// Destroy previous timeline
this.removeTimeline()
this.removeTimeline();
// Check if the widget id is present
var widget = widgetId || this._checkForWidgetId()
var widget = widgetId || this._checkForWidgetId();

if (widget) {
this.Twtt.widgets.createTimeline(widget, this.$.timeline, {
Expand All @@ -90,13 +94,13 @@ var twitterTimeline = function () {
detail: {
loaded: true
}
}))
})
return true
}));
});
return true;
}

console.warn("WARNING: 'data-widget-id' is not defined ")
return false
console.warn("WARNING: 'data-widget-id' is not defined ");
return false;
}

/**
Expand All @@ -105,11 +109,11 @@ var twitterTimeline = function () {

}, {
key: 'removeTimeline',
value: function removeTimeline () {
value: function removeTimeline() {
if (this.$.timeline.querySelector('iframe')) {
return this.$.timeline.removeChild(this.$.timeline.querySelector('iframe'))
return this.$.timeline.removeChild(this.$.timeline.querySelector('iframe'));
}
return false
return false;
}

/** ===============
Expand All @@ -118,37 +122,38 @@ var twitterTimeline = function () {

}, {
key: '_computeLibLink',
value: function _computeLibLink () {
this.$.loaderTwtt.set('lib', 'https://platform.twitter.com/widgets.js')
value: function _computeLibLink() {
this.$.loaderTwtt.set('lib', 'https://platform.twitter.com/widgets.js');
}
}, {
key: '_computeUniqueId',
value: function _computeUniqueId () {
this.$.loaderTwtt.set('libUniqueId', this.uniqueId)
value: function _computeUniqueId() {
this.$.loaderTwtt.set('libUniqueId', this.uniqueId);
}
}, {
key: '_checkForWidgetId',
value: function _checkForWidgetId () {
return this.dataWidgetId || false
value: function _checkForWidgetId() {
return this.dataWidgetId || false;
}
}, {
key: '_onTwttLoad',
value: function _onTwttLoad () {
this.Twtt = window.twttr
this.loadTimeline()
value: function _onTwttLoad() {
this.Twtt = window.twttr;
this.loadTimeline();
}
}, {
key: 'behaviors',

// Define behaviors with a getter.
get: function get () {
return []
get: function get() {
return [];
}
}])
}]);

return twitterTimeline
}()
return twitterTimeline;
}();

// Register the element using Polymer's constructor.

Polymer(twitterTimeline)

Polymer(twitterTimeline);

0 comments on commit 158146d

Please sign in to comment.