share_selected_text-rails 1.0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d6c26ee355d6b142febc634b8e4f26d1eba05d8
4
+ data.tar.gz: 0b00658445975138785c812838f08249b286bead
5
+ SHA512:
6
+ metadata.gz: 545894f0dc337f120003e5c4f6870a773d797b427e45d0c8201f32fc7cd525ec5f3597135a28f9cc98c5732929905b383284b90ac4fb013aefca50e022f98d28
7
+ data.tar.gz: 654d2924de8cdbedb50b3aa30f6ed60d641fe649935038f4f97828ed8048d8f3d01aef958d560b4768b2bbf558294cf79717d7c65d740b28c26289a056e3f9a6
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /share-selected-text
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in share_selected_text-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 WendyBeth
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,81 @@
1
+ # ShareSelectedText::Rails
2
+
3
+ Rails Engine for [share-selected-text](https://github.com/VincentLoy/share-selected-text).
4
+
5
+ > *share selected text on twitter, buffer, and some others. Inspired by [medium.com](http://medium.com)*
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'share_selected_text-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install share_selected_text-rails
22
+
23
+ In app/assets/stylesheets/application.css, add:
24
+
25
+ ```css
26
+ #= require shareSelectedText
27
+ ```
28
+
29
+ In app/assets/javascripts/application.js, add:
30
+
31
+ ```javascript
32
+ //= require shareSelectedText
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Initialize the plugin:
38
+
39
+ ```javascript
40
+ shareSelectedText('.my-super-selector', {
41
+ tooltipClass: '',
42
+ sanitize: true,
43
+ buttons: [
44
+ 'twitter',
45
+ 'buffer'
46
+ ],
47
+ anchorsClass: '',
48
+ twitterUsername: '',
49
+ tooltipTimeout: 250
50
+ });
51
+ ```
52
+
53
+ See [share-selected-text documentation](https://github.com/VincentLoy/share-selected-text/blob/master/README.md) for more information.
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ To draw in latest version of `share-selected-text`:
62
+
63
+ From root path of cloned project:
64
+
65
+ ```bash
66
+ $ git clone https://github.com/VincentLoy/share-selected-text/blob/master/README.md
67
+ ```
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/share_selected_text-rails.
72
+
73
+ ## TODO
74
+
75
+ + Build rake task to pull from share-selected-text, replace vendor/ files
76
+ with updated library, and bump version
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "share_selected_text/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require "share_selected_text/rails/version"
2
+ require "share_selected_text/rails/engine" if defined?(::Rails)
@@ -0,0 +1,6 @@
1
+ module ShareSelectedText
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module ShareSelectedText
2
+ module Rails
3
+ SST_VERSION = "1.0.1"
4
+ VERSION = "#{SST_VERSION}.0"
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'share_selected_text/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "share_selected_text-rails"
8
+ spec.version = ShareSelectedText::Rails::VERSION
9
+ spec.authors = ["WendyBeth"]
10
+ spec.email = ["wendybeth010@gmail.com"]
11
+
12
+ spec.summary = %q{Share Selected Text for Rails}
13
+ spec.description = %q{Assets for share-selected-text for the Rails asset pipeline}
14
+ spec.homepage = "http://github.com/wendybeth/share_selected_text-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+
25
+ spec.add_dependency "railties", '>= 4.0', '< 5.1'
26
+ end
@@ -0,0 +1,56 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
3
+ <!--
4
+ 2016-6-19: Created.
5
+ -->
6
+ <svg xmlns="http://www.w3.org/2000/svg">
7
+ <metadata>
8
+ Created by FontForge 20120731 at Sun Jun 19 18:05:28 2016
9
+ By Vincent Loy,,,
10
+ Created by Vincent Loy,,, with FontForge 2.0 (http://fontforge.sf.net)
11
+ </metadata>
12
+ <defs>
13
+ <font id="sst_icons" horiz-adv-x="512" >
14
+ <font-face
15
+ font-family="sst_icons"
16
+ font-weight="500"
17
+ font-stretch="normal"
18
+ units-per-em="512"
19
+ panose-1="2 0 6 3 0 0 0 0 0 0"
20
+ ascent="448"
21
+ descent="-64"
22
+ bbox="-0.25 -64.25 512 448"
23
+ underline-thickness="25.6"
24
+ underline-position="-51.2"
25
+ unicode-range="U+0020-F10E"
26
+ />
27
+ <missing-glyph />
28
+ <glyph glyph-name="space" unicode=" " horiz-adv-x="200"
29
+ />
30
+ <glyph glyph-name="uniF10E" unicode="&#xf10e;"
31
+ d="M512 351c-14 -21 -32 -40 -53 -55l1 -13c0 -139 -106 -299 -299 -299c-59 0 -115 17 -161 47c8 -1 17 -1 25 -1c49 0 94 17 130 45c-46 1 -85 31 -98 73c6 -1 13 -2 20 -2c10 0 19 1 28 3c-48 10 -84 52 -84 103v2c14 -8 30 -12 47 -13c-28 19 -47 51 -47 87
32
+ c0 19 6 38 15 53c52 -64 129 -106 216 -110c-2 8 -3 16 -3 24c0 58 47 105 105 105c30 0 58 -13 77 -33c24 5 47 13 67 25c-8 -24 -24 -45 -46 -58c21 3 41 9 60 17z" />
33
+ <glyph glyph-name="uniF10C" unicode="&#xf10c;"
34
+ d="M283 242v30c0 15 -12 27 -27 27s-27 -12 -27 -27v-160c0 -63 -51 -115 -114 -115s-115 52 -115 115v67h88v-67c0 -15 12 -27 27 -27s26 12 26 27v160c0 63 52 115 115 115s115 -52 115 -115v-30l-53 -17zM424 179h88v-67c0 -63 -52 -115 -115 -115s-114 52 -114 115v68
35
+ l35 -17l53 17v-68c0 -15 11 -27 26 -27s27 12 27 27v67z" />
36
+ <glyph glyph-name="uniF10D" unicode="&#xf10d;" horiz-adv-x="312"
37
+ d="M312 -36c-22 -10 -41 -18 -59 -22s-37 -6 -57 -6c-23 0 -43 3 -61 9s-33 14 -46 25s-21 23 -26 35s-7 31 -7 54v179h-56v73c20 7 37 16 51 28s25 27 34 44s15 39 18 65h72v-129h120v-81h-120v-131c0 -30 2 -49 5 -57s9 -15 17 -20c11 -7 24 -11 38 -11c26 0 52 9 77 26
38
+ v-81v0z" />
39
+ <glyph glyph-name="uniF10B" unicode="&#xf10b;"
40
+ d="M512 192c0 -11 -2 -21 -8 -30s-13 -16 -23 -21c2 -9 3 -17 3 -27c0 -30 -10 -57 -30 -82s-48 -45 -83 -60s-73 -22 -114 -22s-80 7 -115 22s-62 35 -82 60s-31 52 -31 82c0 9 1 18 3 27c-10 5 -17 12 -23 21s-9 19 -9 30c0 16 6 29 17 40s24 17 40 17s30 -6 41 -18
41
+ c42 29 90 44 147 46l34 149c1 2 2 4 4 6s4 2 7 1l106 -23c3 7 8 13 15 17s15 7 23 7c12 0 22 -5 30 -13s13 -18 13 -30s-5 -22 -13 -30s-18 -13 -30 -13s-22 5 -30 13s-13 18 -13 30l-95 21l-30 -135c57 -2 106 -17 148 -46c11 12 25 18 41 18s29 -6 40 -17s17 -24 17 -40z
42
+ M119 135c0 -12 5 -22 13 -30s18 -13 30 -13s22 5 30 13s13 18 13 30s-5 22 -13 30s-18 13 -30 13s-22 -5 -30 -13s-13 -18 -13 -30zM351 34c2 2 3 4 3 7s-1 6 -3 8s-4 2 -7 2s-6 0 -8 -2c-8 -8 -19 -14 -34 -18s-31 -6 -46 -6s-31 2 -46 6s-26 10 -34 18c-2 2 -5 2 -8 2
43
+ s-5 0 -7 -2s-3 -5 -3 -8s1 -5 3 -7c8 -8 20 -15 34 -20s26 -7 35 -8s18 -1 26 -1s17 0 26 1s21 3 35 8s26 12 34 20zM350 92c12 0 22 5 30 13s13 18 13 30s-5 22 -13 30s-18 13 -30 13s-22 -5 -30 -13s-13 -18 -13 -30s5 -22 13 -30s18 -13 30 -13z" />
44
+ <glyph glyph-name="uniF10A" unicode="&#xf10a;"
45
+ d="M512 137v-190h-110v177c0 44 -15 75 -55 75c-30 0 -49 -21 -57 -41c-3 -7 -3 -16 -3 -26v-185h-110s1 299 0 330h110v-46l-1 -1h1v1c15 22 41 54 99 54c72 0 126 -47 126 -148zM62 437c38 0 60 -25 61 -57c0 -32 -24 -57 -62 -57v0c-37 0 -61 25 -61 57s24 57 62 57z
46
+ M7 -53v330h109v-330h-109z" />
47
+ <glyph glyph-name="uniF109" unicode="&#xf109;"
48
+ d="M196 346c5 0 9 -4 9 -9v-34c0 -5 -4 -9 -9 -9h-34c-5 0 -8 4 -8 9v34c0 5 3 9 8 9h34zM196 274c5 0 9 -4 9 -9v-157c0 -5 -4 -8 -9 -8h-34c-5 0 -8 3 -8 8v157c0 5 3 9 8 9h34zM503 274c5 0 9 -4 9 -9v-218c0 -5 -4 -9 -9 -9h-116c-5 0 -8 4 -8 9v24c0 5 3 8 8 8h65
49
+ c5 0 9 4 9 9v3c0 5 -4 9 -9 9h-65c-5 0 -8 3 -8 8v157c0 5 3 9 8 9h116zM461 149v75c0 5 -4 9 -9 9h-13c-5 0 -9 -4 -9 -9v-75c0 -5 4 -8 9 -8h13c5 0 9 3 9 8zM125 346c5 0 8 -4 8 -9v-229c0 -5 -3 -8 -8 -8h-116c-5 0 -9 3 -9 8v157c0 5 4 9 9 9h64c5 0 9 3 9 8v55
50
+ c0 5 3 9 8 9h35zM82 149v75c0 5 -4 9 -9 9h-13c-5 0 -9 -4 -9 -9v-75c0 -5 4 -8 9 -8h13c5 0 9 3 9 8zM350 274c5 0 8 -4 8 -9v-218c0 -5 -3 -9 -8 -9h-116c-5 0 -9 4 -9 9v24c0 5 4 8 9 8h65c5 0 8 4 8 9v3c0 5 -3 9 -8 9h-65c-5 0 -9 3 -9 8v157c0 5 4 9 9 9h116zM307 149
51
+ v75c0 5 -3 9 -8 9h-14c-5 0 -9 -4 -9 -9v-75c0 -5 4 -8 9 -8h14c5 0 8 3 8 8z" />
52
+ <glyph glyph-name="uniF108" unicode="&#xf108;" horiz-adv-x="511"
53
+ d="M254 448c5 0 10 0 14 -2l233 -97c14 -6 14 -24 0 -29l-233 -101c-8 -3 -19 -3 -28 0l-229 101c-15 8 -15 22 0 29l229 97c3 2 9 2 14 2zM62 230l178 -78c9 -3 18 -4 28 0l182 78l51 -21c14 -8 14 -20 0 -28l-233 -101c-10 -3 -19 -3 -28 0l-229 101c-15 7 -15 21 0 28z
54
+ M62 89l178 -79c9 -3 18 -4 28 0l182 79l51 -21c14 -8 14 -21 0 -29l-233 -101c-10 -3 -19 -3 -28 0l-229 101c-15 7 -15 23 0 29z" />
55
+ </font>
56
+ </defs></svg>
@@ -0,0 +1,276 @@
1
+ /**
2
+ * Created by vincent on 6/15/16.
3
+ */
4
+ 'use strict';
5
+
6
+ (function (exports) {
7
+ 'use strict';
8
+
9
+ var getPageUrl = function getPageUrl() {
10
+ if (document.querySelector('meta[property="og:url"]') && document.querySelector('meta[property="og:url"]').getAttribute('content')) {
11
+ return document.querySelector('meta[property="og:url"]').getAttribute('content');
12
+ }
13
+
14
+ return window.location.href;
15
+ };
16
+
17
+ // constants
18
+ var TOOLTIP_HEIGHT = 50;
19
+ var FACTOR = 1.33;
20
+ var TWITTER_LIMIT_LENGTH = 140;
21
+ var TWITTER_URL_LENGTH_COUNT = 24;
22
+ var TWITTER_QUOTES = 2;
23
+ var TWITTER_DOTS = 3;
24
+ var TOOLTIP_TIMEOUT = 250;
25
+
26
+ var REAL_TWITTER_LIMIT = TWITTER_LIMIT_LENGTH - TWITTER_URL_LENGTH_COUNT - TWITTER_QUOTES - TWITTER_DOTS;
27
+
28
+ var SOCIAL = {
29
+ twitter: 'twitter',
30
+ buffer: 'buffer',
31
+ digg: 'digg',
32
+ linkedin: 'linkedin',
33
+ stumbleupon: 'stumbleupon',
34
+ reddit: 'reddit',
35
+ tumblr: 'tumblr'
36
+ };
37
+
38
+ var NO_START_WITH = /[ .,!?/\\\+\-=*£$€:~§%^µ)(|@"{}&#><_]/g;
39
+ var NO_ENDS_WITH = /[ ,/\\\+\-=*£$€:~§%^µ)(|@"{}&#><_]/g;
40
+ var PAGE_URL = getPageUrl();
41
+
42
+ // globals
43
+ var tooltip = undefined;
44
+ var parameters = undefined;
45
+ var selected = {};
46
+
47
+ var extend = function extend(out) {
48
+ out = out || {};
49
+
50
+ for (var i = 1; i < arguments.length; i += 1) {
51
+ if (arguments[i]) {
52
+ for (var key in arguments[i]) {
53
+ if (arguments[i].hasOwnProperty(key)) {
54
+ out[key] = arguments[i][key];
55
+ }
56
+ }
57
+ }
58
+ }
59
+ return out;
60
+ };
61
+
62
+ var hideTooltip = function hideTooltip() {
63
+ tooltip.classList.remove('active');
64
+ };
65
+
66
+ var showTooltip = function showTooltip() {
67
+ tooltip.classList.add('active');
68
+ };
69
+
70
+ var smartSanitize = function smartSanitize(text) {
71
+ while (text.length && text[0].match(NO_START_WITH)) {
72
+ text = text.substring(1, text.length);
73
+ }
74
+
75
+ while (text.length && text[text.length - 1].match(NO_ENDS_WITH)) {
76
+ text = text.substring(0, text.length - 1);
77
+ }
78
+
79
+ return text;
80
+ };
81
+
82
+ var sanitizeText = function sanitizeText(text) {
83
+ var sociaType = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
84
+
85
+ var author = '';
86
+ var tweetLimit = REAL_TWITTER_LIMIT;
87
+
88
+ if (!text) {
89
+ return '';
90
+ }
91
+
92
+ if (parameters.twitterUsername && sociaType === SOCIAL.twitter) {
93
+ author = ' via @' + parameters.twitterUsername;
94
+ tweetLimit = REAL_TWITTER_LIMIT - author.length;
95
+ }
96
+
97
+ if (text.length > REAL_TWITTER_LIMIT) {
98
+ text = text.substring(0, tweetLimit);
99
+ text = text.substring(0, text.lastIndexOf(' ')) + '...';
100
+ } else {
101
+ text = text.substring(0, tweetLimit + TWITTER_DOTS);
102
+ }
103
+
104
+ return smartSanitize(text);
105
+ };
106
+
107
+ var generateSocialUrl = function generateSocialUrl(socialType, text) {
108
+ if (parameters.sanitize) {
109
+ text = sanitizeText(text, socialType);
110
+ } else {
111
+ text = smartSanitize(text);
112
+ }
113
+
114
+ var twitterUrl = 'https://twitter.com/intent/tweet?url=' + PAGE_URL + '&text="' + text + '"';
115
+
116
+ if (parameters.twitterUsername && parameters.twitterUsername.length) {
117
+ twitterUrl += '&via=' + parameters.twitterUsername;
118
+ }
119
+
120
+ var urls = {
121
+ twitter: twitterUrl,
122
+ buffer: 'https://buffer.com/add?text="' + text + '"&url=' + PAGE_URL,
123
+ digg: 'http://digg.com/submit?url=' + PAGE_URL + '&title=' + text,
124
+ linkedin: 'https://www.linkedin.com/shareArticle?url=' + PAGE_URL + '&title=' + text,
125
+ stumbleupon: 'http://www.stumbleupon.com/submit?url=' + PAGE_URL + '&title=' + text,
126
+ reddit: 'https://reddit.com/submit?url=' + PAGE_URL + '&title=' + text,
127
+ tumblr: 'https://www.tumblr.com/widgets/share/tool?canonicalUrl=' + PAGE_URL + '&caption=' + text
128
+ };
129
+
130
+ if (urls.hasOwnProperty(socialType)) {
131
+ return urls[socialType];
132
+ }
133
+
134
+ return '';
135
+ };
136
+
137
+ var updateTooltip = function updateTooltip(rect) {
138
+ var actualPosition = document.documentElement.scrollTop || document.body.scrollTop;
139
+ var body = document.querySelector('body');
140
+
141
+ tooltip.style.top = actualPosition + rect.top - TOOLTIP_HEIGHT * FACTOR + 'px';
142
+ tooltip.style.left = rect.left + rect.width / 2 - body.getBoundingClientRect().width / 2 + 'px';
143
+
144
+ Array.prototype.forEach.call(parameters.buttons, function (btn) {
145
+ tooltip.querySelector('.share-selected-text-btn-' + btn).href = generateSocialUrl(btn, selected.text);
146
+ });
147
+
148
+ window.setTimeout(function () {
149
+ showTooltip();
150
+ }, parameters.tooltipTimeout);
151
+ };
152
+
153
+ var generateAnchorTag = function generateAnchorTag(anchorType) {
154
+ var customIconClass = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
155
+
156
+ var anchorTag = document.createElement('A');
157
+ var anchorIcon = document.createElement('i');
158
+
159
+ if (parameters.anchorsClass) {
160
+ anchorTag.classList.add('share-selected-text-btn', 'share-selected-text-btn-' + anchorType, '' + parameters.anchorsClass);
161
+ } else {
162
+ anchorTag.classList.add('share-selected-text-btn', 'share-selected-text-btn-' + anchorType);
163
+ }
164
+
165
+ if (customIconClass) {
166
+ anchorIcon.classList.add('' + customIconClass);
167
+ } else {
168
+ anchorIcon.classList.add('icon-sst-' + anchorType, 'fa', 'fa-' + anchorType);
169
+ }
170
+
171
+ anchorIcon.style.pointerEvents = 'none';
172
+ anchorTag.addEventListener('click', function (e) {
173
+ e.preventDefault();
174
+ var windowFeatures = 'status=no,menubar=no,location=no,scrollbars=no,width=720,height=540';
175
+ var url = e.target.href;
176
+ window.open(url, 'Share this post', windowFeatures);
177
+ });
178
+
179
+ anchorTag.href = generateSocialUrl(anchorType, selected.text ? selected.text : '');
180
+ anchorTag.appendChild(anchorIcon);
181
+ return anchorTag;
182
+ };
183
+
184
+ var generateTooltip = function generateTooltip() {
185
+ var body = document.querySelector('body');
186
+ var mainDiv = document.createElement('DIV');
187
+ var btnContainer = document.createElement('DIV');
188
+
189
+ mainDiv.classList.add('share-selected-text-main-container');
190
+ btnContainer.classList.add('share-selected-text-inner');
191
+
192
+ if (parameters.tooltipClass) {
193
+ btnContainer.classList.add(parameters.tooltipClass);
194
+ }
195
+
196
+ mainDiv.style.height = TOOLTIP_HEIGHT + 'px';
197
+ mainDiv.style.top = 0;
198
+ mainDiv.style.left = 0;
199
+
200
+ Array.prototype.forEach.call(parameters.buttons, function (btn) {
201
+ var aTag = generateAnchorTag(btn);
202
+ btnContainer.appendChild(aTag);
203
+ });
204
+
205
+ mainDiv.appendChild(btnContainer);
206
+ body.appendChild(mainDiv);
207
+
208
+ return mainDiv;
209
+ };
210
+
211
+ var getSelectedText = function getSelectedText() {
212
+ var text = '';
213
+ var selection = undefined;
214
+
215
+ if (window.getSelection) {
216
+ selection = window.getSelection();
217
+ text = selection.toString();
218
+ } else if (document.selection && document.selection.type !== 'Control') {
219
+ selection = document.selection.createRange();
220
+ text = selection.text;
221
+ }
222
+
223
+ return {
224
+ selection: selection,
225
+ text: text
226
+ };
227
+ };
228
+
229
+ var shareTooltip = function shareTooltip() {
230
+ selected = getSelectedText();
231
+
232
+ if (selected.text.length) {
233
+ var oRange = selected.selection.getRangeAt(0);
234
+ var oRect = oRange.getBoundingClientRect();
235
+ updateTooltip(oRect);
236
+ } else {
237
+ hideTooltip();
238
+ }
239
+ };
240
+
241
+ exports.shareSelectedText = function (element, args) {
242
+ var elt = document.querySelectorAll(element);
243
+
244
+ parameters = extend({
245
+ tooltipClass: '',
246
+ sanitize: true,
247
+ buttons: [SOCIAL.twitter, SOCIAL.buffer],
248
+ anchorsClass: '',
249
+ twitterUsername: '',
250
+ tooltipTimeout: TOOLTIP_TIMEOUT
251
+ }, args);
252
+
253
+ tooltip = generateTooltip();
254
+
255
+ Array.prototype.forEach.call(elt, function (el) {
256
+ el.addEventListener('mouseup', function () {
257
+ shareTooltip();
258
+ });
259
+ });
260
+ };
261
+ })(window);
262
+
263
+ /*global jQuery, shareSelectedText*/
264
+ if (window.jQuery) {
265
+ (function ($, shareSelected) {
266
+ 'use strict';
267
+
268
+ var shareSelectedify = function shareSelectedify(el, options) {
269
+ shareSelected(el, options);
270
+ };
271
+
272
+ $.fn.shareSelectedText = function (options) {
273
+ return shareSelectedify(this.selector, options);
274
+ };
275
+ })(jQuery, shareSelectedText);
276
+ }
@@ -0,0 +1,51 @@
1
+ @font-face {
2
+ font-family: 'sst_icons';
3
+ src: url('<%= font_path 'sst_icons.eot' %>');
4
+ src: url('<%= font_path 'sst_icons.eot?' %>#iefix') format("embedded-opentype"),
5
+ url('<%= font_path 'sst_icons.woff' %>') format("woff"),
6
+ url('<%= font_path 'sst_icons.ttf' %>') format("truetype"),
7
+ url('<%= font_path 'sst_icons.svg' %>#sst_icons') format("svg");
8
+ font-weight: 400;
9
+ font-style: normal;
10
+ }
11
+
12
+ @media screen and (-webkit-min-device-pixel-ratio: 0) {
13
+ @font-face {
14
+ font-family: 'sst_icons';
15
+ src: url('<%= font_path 'sst_icons.svg' %>#sst_icons') format("svg");
16
+ }
17
+ }
18
+
19
+ [data-icon]:before { content: attr(data-icon) }
20
+
21
+ .icon-sst-buffer:before,
22
+ .icon-sst-digg:before,
23
+ .icon-sst-linkedin:before,
24
+ .icon-sst-reddit:before,
25
+ .icon-sst-stumbleupon:before,
26
+ .icon-sst-tumblr:before,
27
+ .icon-sst-twitter:before,
28
+ [data-icon]:before {
29
+ display: inline-block;
30
+ font-family: 'sst_icons';
31
+ font-style: normal;
32
+ font-weight: 400;
33
+ font-variant: normal;
34
+ line-height: 1;
35
+ text-decoration: inherit;
36
+ text-rendering: optimizeLegibility;
37
+ text-transform: none;
38
+ -moz-osx-font-smoothing: grayscale;
39
+ -webkit-font-smoothing: antialiased;
40
+ font-smoothing: antialiased
41
+ }
42
+
43
+ .icon-sst-buffer:before { content: "\f108" }
44
+ .icon-sst-digg:before { content: "\f109" }
45
+ .icon-sst-linkedin:before { content: "\f10a" }
46
+ .icon-sst-reddit:before { content: "\f10b"}
47
+ .icon-sst-stumbleupon:before { content: "\f10c" }
48
+ .icon-sst-tumblr:before { content: "\f10d" }
49
+ .icon-sst-twitter:before { content: "\f10e" }
50
+
51
+ .share-selected-text-main-container {position: absolute;width: 100%;opacity: 0;-webkit-transform: translateY(5px);-ms-transform:translateY(5px);transform:translateY(5px);transition:.3s ease all;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;z-index:99;pointer-events:none}.share-selected-text-main-container.active{opacity:1;-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0);z-index:999}.share-selected-text-main-container .share-selected-text-inner{-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;background:#404658;height:100%;pointer-events:auto;position:relative}.share-selected-text-main-container .share-selected-text-inner:after{content:'';position:absolute;bottom:-7px;left:0;right:0;margin:auto;width:0;height:0;border-style:solid;border-width:7px 7.5px 0;border-color:#404658 transparent transparent}.share-selected-text-main-container .share-selected-text-btn{display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;text-transform:uppercase;font-weight:700;color:#fff;height:100%;margin:0;padding:0 20px;transition:.2s ease all}.share-selected-text-main-container .share-selected-text-btn:focus,.share-selected-text-main-container .share-selected-text-btn:hover{background:#4f566d}
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: share_selected_text-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - WendyBeth
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '5.1'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '4.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.1'
75
+ description: Assets for share-selected-text for the Rails asset pipeline
76
+ email:
77
+ - wendybeth010@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/share_selected_text-rails.rb
91
+ - lib/share_selected_text/rails/engine.rb
92
+ - lib/share_selected_text/rails/version.rb
93
+ - share_selected_text-rails.gemspec
94
+ - vendor/assets/fonts/sst_icons.eot
95
+ - vendor/assets/fonts/sst_icons.svg
96
+ - vendor/assets/fonts/sst_icons.ttf
97
+ - vendor/assets/fonts/sst_icons.woff
98
+ - vendor/assets/javascripts/shareSelectedText.js
99
+ - vendor/assets/stylesheets/shareSelectedText.scss.erb
100
+ homepage: http://github.com/wendybeth/share_selected_text-rails
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Share Selected Text for Rails
124
+ test_files: []
125
+ has_rdoc: