-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
262 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bower_components | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module.exports = function(grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
|
||
pkg: grunt.file.readJSON('package.json'), | ||
|
||
// tasks | ||
|
||
jshint: { | ||
options: { | ||
jshintrc: 'bower_components/gwa-codestyle/rc/.jshintrc' | ||
}, | ||
src: [ | ||
'src/ShareLinks.js' | ||
] | ||
}, | ||
|
||
jasmine: { | ||
require: { | ||
options: { | ||
vendor: [ | ||
// 'bower_components/requirejs/require.js' | ||
], | ||
specs: [ | ||
'tests/ShareLinks.test.js' | ||
], | ||
template: require('grunt-template-jasmine-requirejs'), | ||
templateOptions: { | ||
requireConfig: { | ||
baseUrl: './', | ||
paths: { | ||
'jquery' : 'bower_components/jquery/dist/jquery', | ||
'Gwa.ShareLinks' : 'src/ShareLinks' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
|
||
copy: { | ||
main: { | ||
files: [ | ||
{src:'src/ShareLinks.js', dest:'dist/ShareLinks.js'} | ||
] | ||
} | ||
}, | ||
|
||
uglify: { | ||
main: { | ||
files: { | ||
'dist/ShareLinks.min.js': ['src/ShareLinks.js'] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-jscs'); | ||
grunt.loadNpmTasks('grunt-contrib-jasmine'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
|
||
grunt.registerTask( | ||
'default', | ||
[ | ||
'jshint:src', | ||
'jasmine', | ||
'copy', | ||
'uglify' | ||
] | ||
); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# Share-Links | ||
Simple non-api share links for Facebook & Twitter | ||
|
||
Simple non-api share links for Facebook & Twitter. | ||
|
||
## Usage | ||
|
||
```markup | ||
<a href="http://linkto.share.com/" class="fb-share">Share on Facebook</a> | ||
<a href="http://linkto.share.com/" data-content="#hashtag content" class="tw-share">Share on Twitter</a> | ||
``` | ||
|
||
```js | ||
gwa.ShareLinks.initFacebook($('a.fb-share')); | ||
gwa.ShareLinks.initTwitter($('a.tw-share')); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "gwa-share-Links", | ||
"main": "", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gwa/Share-Links.git" | ||
}, | ||
"license": "MIT", | ||
"private": true, | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests", | ||
"grunt", | ||
"Gruntfile.js", | ||
"package.json", | ||
"src" | ||
], | ||
"devDependencies": { | ||
"gwa-codestyle": "gwa/codestyle#~1.0", | ||
"requirejs": "~2.1.20" | ||
}, | ||
"dependencies": { | ||
"jquery": ">1.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* global define */ | ||
(function( root, factory ) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(['jquery'], factory); | ||
} else { | ||
// Browser globals | ||
root.gwa = typeof root.gwa === 'undefined' ? {} : root.gwa; | ||
root.gwa.ShareLinks = factory(jQuery); | ||
} | ||
}(this, function($) { | ||
|
||
function getContentData(jq) { | ||
return jq.attr('data-content') ? jq.attr('data-content') : ''; | ||
} | ||
|
||
var instance = { | ||
initFacebook: function(jq) { | ||
jq.on('click', function(ev) { | ||
var permalink = $(this).attr('href'); | ||
ev.preventDefault(); | ||
instance.opener('https://www.facebook.com/sharer.php?u=' + permalink, 'facebook', 'toolbar=no,width=700,height=400'); | ||
}); | ||
}, | ||
|
||
initTwitter: function(jq) { | ||
jq.on('click', function(ev) { | ||
var permalink = $(this).attr('href'), | ||
content = getContentData($(this)), | ||
fullcontent = content ? encodeURIComponent(content + ' ' + permalink) : permalink; | ||
|
||
ev.preventDefault(); | ||
instance.opener('https://www.twitter.com/home?status=' + fullcontent, 'twitter', 'toolbar=no,width=700,height=400'); | ||
}); | ||
}, | ||
|
||
opener: window.open | ||
}; | ||
|
||
return instance; | ||
|
||
})); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "Gwa-Share-Links", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gwa/Share-Links" | ||
}, | ||
"devDependencies": { | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-copy": "^0.8.2", | ||
"grunt-contrib-jasmine": "^0.6.3", | ||
"grunt-contrib-jshint": "^0.11.0", | ||
"grunt-contrib-uglify": "^0.10.0", | ||
"grunt-template-jasmine-requirejs": "^0.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* global define */ | ||
(function( root, factory ) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(['jquery'], factory); | ||
} else { | ||
// Browser globals | ||
root.gwa = typeof root.gwa === 'undefined' ? {} : root.gwa; | ||
root.gwa.ShareLinks = factory(jQuery); | ||
} | ||
}(this, function($) { | ||
|
||
function getContentData(jq) { | ||
return jq.attr('data-content') ? jq.attr('data-content') : ''; | ||
} | ||
|
||
var instance = { | ||
initFacebook: function(jq) { | ||
jq.on('click', function(ev) { | ||
var permalink = $(this).attr('href'); | ||
ev.preventDefault(); | ||
instance.opener('https://www.facebook.com/sharer.php?u=' + permalink, 'facebook', 'toolbar=no,width=700,height=400'); | ||
}); | ||
}, | ||
|
||
initTwitter: function(jq) { | ||
jq.on('click', function(ev) { | ||
var permalink = $(this).attr('href'), | ||
content = getContentData($(this)), | ||
fullcontent = content ? encodeURIComponent(content + ' ' + permalink) : permalink; | ||
|
||
ev.preventDefault(); | ||
instance.opener('https://www.twitter.com/home?status=' + fullcontent, 'twitter', 'toolbar=no,width=700,height=400'); | ||
}); | ||
}, | ||
|
||
opener: window.open | ||
}; | ||
|
||
return instance; | ||
|
||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
define(['jquery', 'Gwa.ShareLinks'], function($, ShareLinks) { | ||
|
||
describe("ShareLinks", function() { | ||
|
||
it("has jquery as a dependency", function () { | ||
expect($).toBeDefined(); | ||
}); | ||
|
||
it("exists as an object", function() { | ||
expect(ShareLinks).toBeDefined(); | ||
}); | ||
|
||
it("can init a FB link", function() { | ||
var result, | ||
jq = $('<a href="http://www.example.com/">My link</a>'); | ||
|
||
ShareLinks.opener = function(url) { | ||
result = url; | ||
}; | ||
|
||
ShareLinks.initFacebook(jq); | ||
jq.trigger('click'); | ||
expect(result).toBe('https://www.facebook.com/sharer.php?u=http://www.example.com/'); | ||
}); | ||
|
||
it("can init a Twitter link", function() { | ||
var result, | ||
jq = $('<a href="http://www.example.com/" data-content="#foo @bar">My link</a>'); | ||
|
||
ShareLinks.opener = function(url) { | ||
result = url; | ||
}; | ||
|
||
ShareLinks.initTwitter(jq); | ||
jq.trigger('click'); | ||
expect(result).toBe('https://www.twitter.com/home?status=%23foo%20%40bar%20http%3A%2F%2Fwww.example.com%2F'); | ||
}); | ||
|
||
}); | ||
|
||
}); |