Skip to content

Commit

Permalink
Merge Juicy/juicy-redirect@2.0.0 into gh-pages
Browse files Browse the repository at this point in the history
# Conflicts:
#	bower.json
#	src/puppet-redirect.html
  • Loading branch information
tomalec committed Dec 7, 2015
2 parents 2ebb800 + 5bcf2b2 commit bbd3f21
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@ module.exports = function(grunt) {
],
// tasks: ['jshint'],
},
},
bump: {
options: {
files: ['package.json', 'bower.json', 'src/juicy-redirect.html'],
commit: true,
commitMessage: '%VERSION%',
commitFiles: ['package.json', 'bower.json', 'src/juicy-redirect.html'],
createTag: true,
tagName: '%VERSION%',
tagMessage: 'Version %VERSION%',
push: false,
// pushTo: 'origin',
globalReplace: false,
prereleaseName: false,
regExp: false
}
}
});

grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-bump');

grunt.registerTask('server', ['connect']);
grunt.registerTask('default', ['watch']);
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Attribute | Options | Default | Description
`url` | *String* | | Destination URL
`url` | `current` | | If a string `"current"` is provided as the URL, the component reloads the page
`history` | | | If attribute `history` is present, the History API `pushState` is used instead of `window.location`
`target` | *String* | `_self` | Target where to open the link. Use `"_blank"` to open in new tab

## Events

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-redirect",
"version": "0.1.3",
"version": "0.2.0",
"description": "Custom Element that redirects to a new URL when an attribute is changed. It's also being listened by PuppetJS.",
"license": "MIT",
"main": "src/puppet-redirect.html",
Expand Down
13 changes: 12 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ <h2>Redirect using <code>window.location</code></h2>
});
</script>

<h3>Open new tab</h3>
<button id="example1_blank">&lt;link is="juicy-redirect" url="/" target="_blank"&gt;</button>

<link is="juicy-redirect" id="redirect1_blank" target="_blank">

<script>
document.getElementById("example1_blank").addEventListener("click", function () {
document.getElementById("redirect1_blank").setAttribute("url", "/");
});
</script>

<h2>Redirect using History API (<code>history.pushState</code>)</h2>
<p>Watch console entries for events logging</p>

Expand All @@ -65,4 +76,4 @@ <h2>Redirect using History API (<code>history.pushState</code>)</h2>
</script>

</body>
</html>
</html>
30 changes: 29 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
{
"private": true
"private": true,
"name": "juicy-redirect",
"description": "> Custom Element that redirects to a new URL when an attribute is changed. It can be configured to work using window location or History API.",
"version": "0.2.0",
"main": "src/juicy-redirect.html",
"dependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+/~https://github.com/Juicy/juicy-redirect.git"
},
"keywords": [
"juicy",
"web-components",
"redirect"
],
"author": "Marcin Warpechowski <marcin@nextgen.pl>",
"license": "MIT",
"bugs": {
"url": "/~https://github.com/Juicy/juicy-redirect/issues"
},
"homepage": "/~https://github.com/Juicy/juicy-redirect#readme",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-bump": "^0.3.0",
"grunt-cli": "^0.1.13"
}
}
7 changes: 5 additions & 2 deletions src/puppet-redirect.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- puppet-redirect v0.1.3 | MIT License -->
<!-- puppet-redirect version:0.1.3 | MIT License -->
<script>
(function (global) {
var PuppetRedirectElementPrototype = Object.create(HTMLLinkElement.prototype);
Expand All @@ -25,7 +25,10 @@
if(url == "current") {
url = window.location.href;
}
if(this.hasAttribute("history")) {
var target = this.getAttribute("target");
if(target && target !== '_self'){
window.open(url, this.getAttribute("target"));
} else if(this.hasAttribute("history")) {
history.pushState(null, null, url);
this.dispatchEvent(
new CustomEvent(
Expand Down

0 comments on commit bbd3f21

Please sign in to comment.