From 8824578963f1aca98afa9517759dd792c0fd59c3 Mon Sep 17 00:00:00 2001 From: Tomek Wytrebowicz Date: Wed, 1 Oct 2014 13:50:34 +0200 Subject: [PATCH] Do not redirect if no url given --- src/juicy-redirect.html | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/juicy-redirect.html b/src/juicy-redirect.html index ec3c07e..d67c39d 100755 --- a/src/juicy-redirect.html +++ b/src/juicy-redirect.html @@ -17,32 +17,29 @@ break; } }; - JuicyRedirectElementPrototype.redirect = function(newVal){ - var url; - if(newVal == "current") { + JuicyRedirectElementPrototype.redirect = function(url){ + if(!url){ + return false; + } + if(url == "current") { url = window.location.href; } - else { - url = newVal; + if(this.hasAttribute("history")) { + history.pushState(null, null, url); + this.dispatchEvent( + new CustomEvent( + "juicy-redirect-pushstate", + { + "detail":{"url":url}, + "bubbles": true + } + ) + ); } - if(url != "") { - if(this.hasAttribute("history")) { - history.pushState(null, null, url); - this.dispatchEvent( - new CustomEvent( - "juicy-redirect-pushstate", - { - "detail":{"url":url}, - "bubbles": true - } - ) - ); - } - else { - window.location = url; - } - this.setAttribute("url", ""); + else { + window.location = url; } + this.setAttribute("url", ""); return url; }