Skip to content

Commit 2620d2d

Browse files
author
Tom Milewski
committed
Merge pull request carrot#69 from carrot/vanillajs
Remove jQuery Dependency
2 parents 7cb922b + 19f9c0f commit 2620d2d

File tree

10 files changed

+854
-408
lines changed

10 files changed

+854
-408
lines changed

Cakefile

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ accord = require 'accord'
77
stylus = accord.load('stylus')
88
axis = require 'axis-css'
99
autoprefixer = require 'autoprefixer-stylus'
10-
uuid = require 'node-uuid'
1110
monocle = require 'monocle'
11+
umd = require 'umd'
1212

1313
# tasks
1414

@@ -39,45 +39,47 @@ task 'watch', 'rebuild on change in src folder', ->
3939
# logic
4040

4141
class Builder
42-
4342
constructor: ->
44-
@js_path = path.join(__dirname, 'src/share.coffee')
43+
@utils_js_path = path.join(__dirname, 'src/share_utils.coffee')
44+
@share_js_path = path.join(__dirname, 'src/share.coffee')
4545
@css_path = path.join(__dirname, 'src/styles.styl')
4646

4747
build: (opts) ->
4848
@opts = opts || {}
4949
@compile_css().then(@compile_js.bind(@))
5050

5151
compile_css: (opts) ->
52-
tokens = set_tokens(['selector', 'button_color', 'button_background'])
52+
tokens = ['config.selector', "config.ui.button_color", "config.ui.button_background"]
5353

54-
stylus.renderFile(@css_path, { use: [define_tokens(tokens), axis(), autoprefixer()] })
54+
stylus.renderFile(@css_path, { use: [axis(), autoprefixer()] })
5555
.then((css) ->
5656
accord.load('minify-css').render(css).then (css) ->
57-
return "<style>#{replace_tokens(css, tokens)}</style>"
57+
return replace_tokens(css, tokens)
5858
).then (css) ->
5959
"function getStyles(config){ return \"#{css}\"};"
6060

6161
compile_js: (css) ->
62-
accord.load('coffee-script').renderFile(@js_path, { bare: true })
63-
.then (js) =>
64-
if @opts.minify
65-
accord.load('minify-js').render(js).then (js) ->
66-
"!function(){#{css}#{js}}.call(this)"
67-
else
68-
return "!function(){#{css}#{js}}.call(this)"
62+
cs = accord.load('coffee-script')
63+
cs.renderFile(@utils_js_path, { bare: true })
64+
.then (utils_js) =>
65+
cs.renderFile(@share_js_path, { bare: true })
66+
.then (share_js) =>
67+
if @opts.minify
68+
accord.load('minify-js').render("#{utils_js}#{share_js}").then (js) ->
69+
"#{css}#{js}"
70+
else
71+
"#{css}#{utils_js}#{share_js}"
72+
.then (out) ->
73+
umd('Share', "#{out} return Share;")
74+
6975

7076
#
7177
# @api private
7278
#
7379

74-
set_tokens = (arr) ->
75-
arr.reduce(((m,v) -> m[v] = uuid.v1(); m), {})
76-
7780
replace_tokens = (res, tokens) ->
78-
for k, v of tokens
79-
res = res.replace(new RegExp(v, 'g'), "\"+config.#{k}+\"")
80-
return res
81+
for token in tokens
82+
normalized_token = token.replace(/\./g, "-")
83+
res = res.replace(new RegExp(normalized_token, 'g'), "\"+#{token}+\"")
8184

82-
define_tokens = (tokens) ->
83-
return (style) -> style.define(k, v) for k, v of tokens
85+
return res

build/share.js

Lines changed: 373 additions & 127 deletions
Large diffs are not rendered by default.

build/share.min.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples.html

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,51 @@
1313
<meta name='og:image' content='http://carrot.is/img/fb-share.jpg'>
1414
</head>
1515
<body>
16-
<a class='fork' href="https://github.com/carrot/share-button"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://www.sharebutton.co/images/fork-me.png" alt="Fork me on GitHub"></a>
16+
<a class='fork' href="https://github.com/carrot/share-button">
17+
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://www.sharebutton.co/images/fork-me.png" alt="Fork me on GitHub">
18+
</a>
1719
<div class='share-button share-button-top'></div>
1820
<div class='share-button share-button-left'></div>
1921
<div class='share-button share-button-bottom'></div>
2022
<div class='share-button share-button-bottom'></div>
21-
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js'></script>
2223
<script src='build/share.js'></script>
2324
<script>
24-
$(function(){
25-
$('.share-button-top').share({
26-
title: 'Share Button Mutiple Element Test',
27-
image: 'http://carrot.is/img/fb-share.jpg',
28-
app_id: '602752456409826',
29-
background: 'rgba(255,255,255,.5)',
30-
color: '#3B2B45',
31-
flyout: 'top center'
32-
});
25+
var share_button_top = new Share(".share-button-top", {
26+
title: "Share Button Multiple Element Test",
27+
ui: {
28+
flyout: "top center"
29+
},
30+
networks: {
31+
facebook: {
32+
app_id: "602752456409826",
33+
}
34+
}
35+
});
3336

34-
$('.share-button-left').share({
35-
title: 'Share Button Multiple Instantiation Test',
36-
image: 'http://carrot.is/img/fb-share.jpg',
37-
app_id: '602752456409826',
38-
background: 'rgba(255,255,255,.5)',
39-
color: '#3B2B45',
40-
flyout: 'bottom left'
41-
});
37+
var share_button_left = new Share(".share-button-left", {
38+
title: "Share Button Multiple Instantiation Test",
39+
ui: {
40+
flyout: "top left",
41+
button_text: "Left"
42+
},
43+
networks: {
44+
facebook: {
45+
app_id: "602752456409826",
46+
}
47+
}
48+
});
4249

43-
$('.share-button-bottom').share({
44-
title: 'Share Button Multiple Instantiation Test',
45-
image: 'http://carrot.is/img/fb-share.jpg',
46-
app_id: '602752456409826',
47-
background: 'rgba(255,255,255,.5)',
48-
color: '#3B2B45',
49-
flyout: 'top right'
50-
});
50+
var share_button_right = new Share(".share-button-bottom", {
51+
title: "Share Button Multiple Instantiation Test",
52+
ui: {
53+
flyout: "bottom right",
54+
button_text: "Right"
55+
},
56+
networks: {
57+
facebook: {
58+
app_id: "602752456409826",
59+
}
60+
}
5161
});
5262
</script>
5363
</body>

index.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@
1313
<meta name='og:image' content='http://carrot.is/img/fb-share.jpg'>
1414
</head>
1515
<body>
16-
<a class='fork' href="https://github.com/carrot/share-button"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://www.sharebutton.co/images/fork-me.png" alt="Fork me on GitHub"></a>
17-
<div class='share-button share-button-top'></div>
18-
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js'></script>
16+
<a class='fork' href="https://github.com/carrot/share-button">
17+
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://www.sharebutton.co/images/fork-me.png" alt="Fork me on GitHub">
18+
</a>
19+
<div id="share-button-top" class='share-button share-button-top'></div>
1920
<script src='build/share.js'></script>
2021
<script>
21-
$(function(){
22-
$('.share-button').share({
23-
title: 'Share Button Test',
24-
image: 'http://carrot.is/img/fb-share.jpg',
25-
app_id: '602752456409826',
26-
background: 'rgba(255,255,255,.5)',
27-
color: '#3B2B45',
28-
flyout: 'top center',
29-
text_font: true
30-
});
22+
var share = new Share("#share-button-top", {
23+
networks: {
24+
facebook: {
25+
app_id: "602752456409826",
26+
}
27+
}
3128
});
3229
</script>
3330
</body>

package.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
{
22
"name": "share-button",
3-
"version": "0.0.5",
4-
"author": "Jeff Escalante <[email protected]>",
53
"description": "fast, beautiful, and painless social shares",
4+
"version": "0.1.0",
5+
"homepage": "http://sharebutton.co",
6+
"bugs": {
7+
"url": "https://github.com/carrot/share-button/issues"
8+
},
9+
"author": "Jeff Escalante <[email protected]>",
10+
"contributors": [
11+
{
12+
"name": "Tom Milewski",
13+
"email": "[email protected]"
14+
}
15+
],
616
"repository": {
717
"type": "git",
818
"url": "https://github.com/carrot/share-button"
919
},
1020
"license": "MIT",
21+
"dependencies": {},
1122
"devDependencies": {
1223
"mocha": "*",
1324
"should": "*",
@@ -20,11 +31,16 @@
2031
"clean-css": "2.x.x",
2132
"coffee-script": "1.x.x",
2233
"uglifyjs": "2.x.x",
23-
"node-uuid": "1.x.x",
2434
"colors": "0.6.x",
25-
"monocle": "1.x.x"
35+
"monocle": "1.x.x",
36+
"umd": "~2.0.0"
2637
},
2738
"scripts": {
2839
"test": "mocha test"
29-
}
40+
},
41+
"keywords": [
42+
"share",
43+
"social"
44+
],
45+
"engines": {}
3046
}

0 commit comments

Comments
 (0)