├── .gitignore ├── screenshot.png ├── package.json ├── gulpfile.js ├── README.md ├── src ├── inline-tweet.min.js └── inline-tweet.js ├── index.html └── style.css /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ireade/inlinetweetjs/HEAD/screenshot.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inline-tweet-js", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "gulpfile.js", 6 | "devDependencies": { 7 | "gulp": "^3.9.1", 8 | "gulp-util": "^3.0.7", 9 | "gulp-uglifyjs": "^0.6.2" 10 | }, 11 | "scripts": { 12 | "start": "gulp" 13 | }, 14 | "author": "Ire Aderinokun", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | gutil = require('gulp-util'), 3 | uglify = require('gulp-uglifyjs'); 4 | 5 | gulp.task('script', function() { 6 | gulp.src('src/inline-tweet.js') 7 | .pipe( 8 | uglify('inline-tweet.min.js') 9 | .on('error', gutil.log) 10 | ) 11 | .pipe(gulp.dest('src')); 12 | }); 13 | 14 | gulp.task('watch', function() { 15 | gulp.watch('src/inline-tweet.js',['script']); 16 | }); 17 | 18 | gulp.task('default', ['script', 'watch']); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InlineTweet.js 2 | 3 | ![InlineTweet.js allows you to easily create tweetable links out of any text on a webpage. Just wrap the tweetable text in a container with data-inline-tweet and you're good to go!](screenshot.png) 4 | 5 | [SEE DEMO](http://ireade.github.io/inlinetweetjs/) 6 | 7 | Want to use this in Wordpress? [Check out this plugin](https://github.com/ireade/wp-inlinetweetjs/) 8 | 9 | 10 | ## How to Use 11 | 12 | 13 | #### 1 - Include Script 14 | 15 | [Download the file from here](https://raw.githubusercontent.com/ireade/inlinetweetjs/gh-pages/src/inline-tweet.min.js) and include it in your webpage. 16 | 17 | ```html 18 | 19 | ``` 20 | 21 | 22 | #### 2 - Wrap Text 23 | 24 | Wrap the tweetable text in a container element of your choice (`span` recommended) with the data attribute, `data-inline-tweet` 25 | 26 | 27 | ```html 28 | Lorem Khaled Ipsum is a major key to success 29 | ``` 30 | 31 | 32 | #### 3 - Additional Options 33 | 34 | You can add more data attributes to cutomise the tweeted output - 35 | 36 | - `data-inline-tweet-via` — Add a twitter username (without the @) to append to the tweet 37 | - `data-inline-tweet-tags` - Add hashtags to the tweet (comma-separated, no spaces) 38 | - `data-inline-tweet-url` — Tweet a URL different to the current page url 39 | 40 | ```html 41 | 45 | Lorem Khaled Ipsum is a major key to success 46 | 47 | ``` 48 | 49 | 50 | #### 4 - Add Styles 51 | 52 | Add the following styles to your stylesheet - 53 | 54 | ```css 55 | [data-inline-tweet] a { 56 | text-decoration: none; 57 | color: #000; 58 | } 59 | [data-inline-tweet] a span { 60 | border-bottom: 1px dotted rgb(0,172,237); 61 | font-style: italic; 62 | margin-right: 10px; 63 | } 64 | [data-inline-tweet] a:hover span { 65 | background-color: rgba(0,172,237,0.1); 66 | color: rgb(0,172,237); 67 | } 68 | ``` 69 | 70 | 71 | ## Licence 72 | 73 | [GNU GENERAL PUBLIC LICENSE](https://www.gnu.org/licenses/gpl-3.0.en.html) 74 | 75 | -------------------------------------------------------------------------------- /src/inline-tweet.min.js: -------------------------------------------------------------------------------- 1 | function buildInlineTweet(e){var t=e.innerHTML,i="%22"+encodeURIComponent(t)+"%22",n=e.dataset.inlineTweetUrl?e.dataset.inlineTweetUrl:window.location.href,a=e.dataset.inlineTweetVia?"&via="+e.dataset.inlineTweetVia:"",r=e.dataset.inlineTweetTags?"&hashtags="+e.dataset.inlineTweetTags:"",l="https://twitter.com/intent/tweet/?text="+i+"&url="+n+a+r,d=document.createElement("span");d.innerHTML=t;var s=document.createElement("a");s.target="_blank",s.href=l,s.appendChild(d),s.innerHTML+=twitterLogo,e.innerHTML="",e.appendChild(s)}var inlineTweets=document.querySelectorAll("*[data-inline-tweet]");if(inlineTweets)for(var twitterLogo='image/svg+xml',i=0;i 2 | 3 | 4 | 5 | InlineTweet.js 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 |
17 | 18 |

InlineTweet.js

19 | 20 |

InlineTweet.js allows you to easily create tweetable links out of any text on a webpage. Just wrap the tweetable text in a container with data-inline-tweet and you're good to go!

21 | 22 |
23 | 24 | 25 | 26 |

27 | 28 |

29 | UPDATE: 30 | You can now use InlineTweet.js in Wordpress with this new plugin! 31 | 32 | (Check it out) 33 |

34 | 35 | 36 |
37 | 38 | 39 |
40 |

How To Use

41 | 42 |
43 |

1 - Include Script

44 | 45 |

Download the file from here and include it in your webpage.

46 |
<script src="path/to/inline-tweet.min.js"></script>
47 |
48 | 49 | 50 |
51 |

2 - Wrap Text

52 | 53 |

Wrap the tweetable text in a container element of your choice (span recommended) with the data attribute, data-inline-tweet

54 | 55 |
<span data-inline-tweet>Lorem Khaled Ipsum is a major key to success</span>
56 |
57 | 58 | 59 |
60 |

3 - Additional Options

61 | 62 |

You can add more data attributes to cutomise the tweeted output -

63 |
    64 |
  • data-inline-tweet-via — Add a twitter username (without the @) to append to the tweet
  • 65 |
  • data-inline-tweet-tags - Add hashtags to the tweet (comma-separated, no spaces)
  • 66 |
  • data-inline-tweet-url — Tweet a URL different to the current page url
  • 67 |
68 |
<span data-inline-tweet
 69 |       data-inline-tweet-via="ireaderinokun"
 70 |       data-inline-tweet-tags="webdesign,webdev,js,yolo"
 71 |       data-inline-tweet-url="bitsofco.de">
 72 |   Lorem Khaled Ipsum is a major key to success
 73 | </span>
74 |
75 | 76 | 77 |
78 |

4 - Add Styles

79 |

Add the following styles to your stylesheet -

80 | 81 |
[data-inline-tweet] a {
 82 |   text-decoration: none;
 83 |   color: #000;
 84 | }
 85 | [data-inline-tweet] a span {
 86 |   border-bottom: 1px dotted rgb(0,172,237);
 87 |   font-style: italic;
 88 |   margin-right: 10px;
 89 | }
 90 | [data-inline-tweet] a:hover span {
 91 |   background-color: rgba(0,172,237,0.1);
 92 |   color: rgb(0,172,237);
 93 | }
94 |
95 | 96 | 97 |
98 | 99 | 100 |

Made with by @IreAderinokun

101 | 102 |
103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | html, body, div, span, applet, object, iframe, 2 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 3 | a, abbr, acronym, address, big, cite, code, 4 | del, dfn, em, img, ins, kbd, q, s, samp, 5 | small, strike, strong, sub, sup, tt, var, 6 | b, u, i, center, 7 | dl, dt, dd, ol, ul, li, 8 | fieldset, form, label, legend, 9 | table, caption, tbody, tfoot, thead, tr, th, td, 10 | article, aside, canvas, details, embed, 11 | figure, figcaption, footer, header, hgroup, 12 | menu, nav, output, ruby, section, summary, 13 | time, mark, audio, video { 14 | margin: 0; 15 | padding: 0; 16 | border: 0; 17 | font: inherit; 18 | font-size: 100%; 19 | vertical-align: baseline; 20 | } 21 | 22 | article, aside, details, figcaption, figure, 23 | footer, header, hgroup, menu, nav, section { 24 | display: block; 25 | } 26 | ul { 27 | list-style: none; 28 | } 29 | blockquote, q { 30 | quotes: none; 31 | } 32 | blockquote:before, blockquote:after, 33 | q:before, q:after { 34 | content: ''; 35 | content: none; 36 | } 37 | table { 38 | border-collapse: collapse; 39 | border-spacing: 0; 40 | } 41 | 42 | /* Box sizing */ 43 | 44 | html { 45 | box-sizing: border-box; 46 | } 47 | 48 | *, *:before, *:after { 49 | box-sizing: inherit; 50 | } 51 | 52 | 53 | 54 | 55 | /* ---------------*/ 56 | 57 | 58 | 59 | html { 60 | font-size: 62.5%; 61 | } 62 | body { 63 | font-size: 1.6rem; 64 | line-height: 1.4; 65 | font-family: 'Source Sans Pro', sans-serif; 66 | color: rgb(50, 50, 50); 67 | 68 | } 69 | a { 70 | color: inherit; 71 | } 72 | 73 | small { 74 | font-size: 1rem; 75 | display: block; 76 | text-align: right; 77 | } 78 | strong { 79 | font-weight: 600; 80 | } 81 | 82 | h1 { 83 | font-size: 4rem; 84 | margin-bottom: 20px; 85 | font-weight: 600; 86 | } 87 | 88 | 89 | 90 | 91 | p.about { 92 | font-size: 2rem; 93 | margin-bottom: 20px; 94 | } 95 | 96 | p { 97 | margin-bottom: 15px; 98 | } 99 | 100 | h2 { 101 | font-size: 2.5rem; 102 | font-weight: 600; 103 | margin-bottom: 20px; 104 | } 105 | 106 | 107 | h3 { 108 | font-size: 2rem; 109 | font-weight: 600; 110 | margin-bottom: 20px; 111 | } 112 | 113 | .uo { 114 | color: rgb(180, 180, 180); 115 | } 116 | 117 | 118 | .ul { 119 | display: block; 120 | margin-bottom: 20px; 121 | margin-left: 20px; 122 | 123 | } 124 | 125 | .ul li { 126 | list-style-type: disc; 127 | list-style-position: inside; 128 | } 129 | 130 | .container { 131 | margin: 100px auto; 132 | width: 90%; 133 | max-width: 800px; 134 | } 135 | 136 | @media screen and (max-width: 600px) { 137 | .container { 138 | margin: 50px auto; 139 | } 140 | } 141 | 142 | 143 | 144 | section.site-section { 145 | margin-bottom: 50px; 146 | padding-bottom: 30px; 147 | border-bottom: 1px solid rgb(220, 220, 220); 148 | } 149 | section:not(.site-section) { 150 | margin-bottom: 40px; 151 | } 152 | 153 | .highlight { 154 | margin-bottom: 15px; 155 | } 156 | 157 | pre { 158 | background-color: rgb(220, 220, 220); 159 | padding: 10px; 160 | display: block; 161 | font-family: 'Source Code Pro', monospace; 162 | font-size: 1.2rem; 163 | color: #000; 164 | 165 | white-space: pre-line; 166 | word-wrap: break-word; 167 | position: relative; 168 | } 169 | 170 | code { 171 | background-color: rgb(220, 220, 220); 172 | font-family: 'Source Code Pro', monospace; 173 | font-size: 1.2rem; 174 | color: #000; 175 | padding: 2px 5px; 176 | } 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | /* Twemoji Awesome - http://ellekasai.github.io/twemoji-awesome/ */ 191 | .twa { 192 | display: inline-block; 193 | height: 1em; 194 | width: 1em; 195 | margin: 0 .05em 0 .1em; 196 | vertical-align: -0.1em; 197 | background-repeat: no-repeat; 198 | background-position: center center; 199 | background-size: 1em 1em; } 200 | 201 | .twa-heart { 202 | background-image: url("https://twemoji.maxcdn.com/svg/2764.svg"); 203 | } 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | [data-inline-tweet] a { 213 | text-decoration: none; 214 | color: #000; 215 | } 216 | [data-inline-tweet] a span { 217 | border-bottom: 1px dotted rgb(0,172,237); 218 | font-style: italic; 219 | margin-right: 8px; 220 | } 221 | [data-inline-tweet] a:hover span { 222 | background-color: rgba(0,172,237, 0.1); 223 | color: rgb(0,172,237); 224 | } 225 | 226 | 227 | 228 | 229 | 230 | --------------------------------------------------------------------------------