├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example ├── basic.js └── choo.js ├── index.js ├── loader.js ├── package.json ├── screenshot.png └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .nyc_output/ 3 | coverage/ 4 | dist/ 5 | tmp/ 6 | npm-debug.log* 7 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: node_js 3 | node_js: 4 | - 'node' 5 | sudo: false 6 | addons: 7 | apt: 8 | packages: 9 | - xvfb 10 | cache: 11 | directories: 12 | - ~/.npm 13 | install: 14 | - export DISPLAY=':99.0' 15 | - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & 16 | - npm i 17 | script: 18 | - npm test 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # twitter-component Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## 1.0.2 - 2017-09-11 6 | * Add nanoassert as [browser dependency](https://github.com/browserify/browserify-handbook#browser-field). 7 | * Add yo-yoify as a [local transform](https://github.com/browserify/browserify-handbook#browserifytransform-field). 8 | 9 | ## 1.0.1 - 2017-08-19 10 | * Fix sibling re-ordering 11 | * Add option to disable placeholder text 12 | 13 | ## 1.0.0 - 2017-08-17 14 | * Engage 🚀 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Bret Comnes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # twitter-component [![stability][0]][1] 2 | [![npm version][2]][3] [![build status][4]][5] 3 | [![downloads][8]][9] [![js-standard-style][10]][11] 4 | 5 | A native DOM component wrapper for embedded tweets. 6 | 7 |  8 | 9 | ## Usage 10 | 11 | ```js 12 | // Vanilla JS example 13 | var TwitterComponent = require('twitter-component') 14 | 15 | var tweet1 = new TwitterComponent() 16 | var tweet2 = new TwitterComponent() 17 | 18 | document.body.appendChild(tweet1.render('https://twitter.com/uhhyeahbret/status/897603426518876161')) 19 | document.body.appendChild(tweet2.render('https://twitter.com/yoshuawuyts/status/895338700531535878')) 20 | 21 | ``` 22 | 23 | ## Installation 24 | ```sh 25 | $ npm install twitter-component 26 | ``` 27 | ## API 28 | ### `TwitterComponent = require('twitter-component`) 29 | Import `TwitterComponent` component class. 30 | 31 | ### `tweet = new TwitterComponent([opts])` 32 | Create a new instance of the twitter component. `opts` is an options objec that can have the following options: 33 | 34 | ```js 35 | { 36 | placeholder: true // Enables placeholder text while loading tweet cards 37 | } 38 | ``` 39 | 40 | ### `tweet.render(tweetURL)` 41 | Returns a div that, when mounted into the page, will be the target of `twttr.widgets.createTweet`. 42 | Mounting the DOM node returned by `.render` will also load `platform.twitter.com/widgets.js` into the page, and any other side-effects and visitor tracking implications that script brings along with it. 43 | 44 | **Twitter employees:** Please release a module version of `platform.twitter.com/widgets.js` because this took 5 hours of freetime™ of just trying to get caught up with your ever changing API and widget ecosystem. 45 | 46 | Native DOM component model powered by [nanocomponent][nc] and [nanomorph][nm]. 47 | 48 | ## License 49 | [MIT](https://tldrlegal.com/license/mit-license) 50 | 51 | [0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square 52 | [1]: https://nodejs.org/api/documentation.html#documentation_stability_index 53 | [2]: https://img.shields.io/npm/v/twitter-component.svg?style=flat-square 54 | [3]: https://npmjs.org/package/twitter-component 55 | [4]: https://img.shields.io/travis/bcomnes/twitter-component/master.svg?style=flat-square 56 | [5]: https://travis-ci.org/bcomnes/twitter-component 57 | [8]: http://img.shields.io/npm/dm/twitter-component.svg?style=flat-square 58 | [9]: https://npmjs.org/package/twitter-component 59 | [10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 60 | [11]: https://github.com/feross/standard 61 | [bel]: https://github.com/shama/bel 62 | [yoyoify]: https://github.com/shama/yo-yoify 63 | [md]: https://github.com/patrick-steele-idem/morphdom 64 | [210]: https://github.com/patrick-steele-idem/morphdom/pull/81 65 | [nm]: https://github.com/yoshuawuyts/nanomorph 66 | [ce]: https://github.com/yoshuawuyts/cache-element 67 | [class]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes 68 | [isSameNode]: https://github.com/choojs/nanomorph#caching-dom-elements 69 | [onload]: https://github.com/shama/on-load 70 | [choo]: https://github.com/choojs/choo 71 | [nca]: https://github.com/choojs/nanocomponent-adapters 72 | [nc]: https://github.com/choojs/nanocomponent 73 | -------------------------------------------------------------------------------- /example/basic.js: -------------------------------------------------------------------------------- 1 | var Tweet = require('../') 2 | 3 | var tweet1 = new Tweet() 4 | var tweet2 = new Tweet() 5 | 6 | document.body.appendChild(tweet1.render('https://twitter.com/uhhyeahbret/status/897603426518876161')) 7 | document.body.appendChild(tweet2.render('https://twitter.com/yoshuawuyts/status/895338700531535878')) 8 | -------------------------------------------------------------------------------- /example/choo.js: -------------------------------------------------------------------------------- 1 | var html = require('choo/html') 2 | var choo = require('choo') 3 | var Nanomap = require('nanomap') 4 | var twitterFeed = require('noauth-twitterfeed') 5 | var Tweet = require('../') 6 | 7 | var app = choo() 8 | app.use(tweetStore) 9 | app.route('/', mainView) 10 | if (typeof window !== 'undefined') app.mount('body') 11 | 12 | var tweetMap = new Nanomap(Tweet) 13 | 14 | function shape (tweet, i, array) { 15 | return { 16 | id: tweet.url, 17 | arguments: tweet.url 18 | } 19 | } 20 | 21 | function mainView (state, emit) { 22 | function onInput (ev) { 23 | emit('input', ev.target.value) 24 | } 25 | 26 | function onUpdate (ev) { 27 | console.log('click') 28 | emit('update') 29 | } 30 | 31 | return html` 32 |
33 |