Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. kmallea revised this gist Oct 1, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion uriSchemeWithHyperlinkFallback.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    function uriSchemeWithHyperlinkFallback(e,t){var n=(new Date).getTime(),r,i;document.location=e;r=(new Date).getTime();i=r-n;if(i<1){document.location=t}}
  2. kmallea revised this gist Oct 1, 2013. 1 changed file with 2 additions and 18 deletions.
    20 changes: 2 additions & 18 deletions uriSchemeWithHyperlinkFallback.js
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,6 @@
    // tries to execute the uri:scheme
    function uriSchemeWithHyperlinkFallback(uri, href) {
    // set up a timer and start it
    var start = new Date().getTime(),
    end,
    elapsed;

    // attempt to redirect to the uri:scheme
    // the lovely thing about javascript is that it's single threadded.
    // if this WORKS, it'll stutter for a split second, causing the timer to be off
    document.location = uri;

    // end timer
    end = new Date().getTime();

    elapsed = (end - start);

    // if there's no elapsed time, then the scheme didn't fire, and we head to the url.
    if (elapsed < 1) {
    document.location = href;
    if(!window.open(uri)){
    window.location = href;
    }
    }
  3. @ChaseFlorell ChaseFlorell revised this gist May 2, 2013. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions uriSchemeWithHyperlinkFallback.min.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    function uriSchemeWithHyperlinkFallback(e,t){var n=(new Date).getTime(),r,i;document.location=e;r=(new Date).getTime();i=r-n;if(i<1){document.location=t}}
    2 changes: 1 addition & 1 deletion x-demo.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="uriSchemeWithHyperlinkFallback.js"></script>
    <script src="uriSchemeWithHyperlinkFallback.min.js"></script>
    </head>
    <body>
    <!-- links will work as expected where javascript is disabled-->
  4. @ChaseFlorell ChaseFlorell revised this gist May 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion uriSchemeWithHyperlinkFallback.js
    Original file line number Diff line number Diff line change
    @@ -19,4 +19,4 @@ function uriSchemeWithHyperlinkFallback(uri, href) {
    if (elapsed < 1) {
    document.location = href;
    }
    };
    }
  5. @ChaseFlorell ChaseFlorell revised this gist May 2, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions uriSchemeWithHyperlinkFallback.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    // tries to execute the uri:scheme
    function uriSchemeWithHyperlinkFallback(uri, href) {
    var start, end, elapsed;

    // start a timer
    start = new Date().getTime();
    // set up a timer and start it
    var start = new Date().getTime(),
    end,
    elapsed;

    // attempt to redirect to the uri:scheme
    // the lovely thing about javascript is that it's single threadded.
  6. @ChaseFlorell ChaseFlorell revised this gist May 2, 2013. 1 changed file with 17 additions and 17 deletions.
    34 changes: 17 additions & 17 deletions uriSchemeWithHyperlinkFallback.js
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,22 @@
    // tries to execute the uri:scheme
    function uriSchemeWithHyperlinkFallback(uri, href) {
    var start, end, elapsed;
    // tries to execute the uri:scheme
    function uriSchemeWithHyperlinkFallback(uri, href) {
    var start, end, elapsed;

    // start a timer
    start = new Date().getTime();
    // start a timer
    start = new Date().getTime();

    // attempt to redirect to the uri:scheme
    // the lovely thing about javascript is that it's single threadded.
    // if this WORKS, it'll stutter for a split second, causing the timer to be off
    document.location = uri;
    // attempt to redirect to the uri:scheme
    // the lovely thing about javascript is that it's single threadded.
    // if this WORKS, it'll stutter for a split second, causing the timer to be off
    document.location = uri;

    // end timer
    end = new Date().getTime();
    // end timer
    end = new Date().getTime();

    elapsed = (end - start);
    elapsed = (end - start);

    // if there's no elapsed time, then the scheme didn't fire, and we head to the url.
    if (elapsed < 1) {
    document.location = href;
    }
    };
    // if there's no elapsed time, then the scheme didn't fire, and we head to the url.
    if (elapsed < 1) {
    document.location = href;
    }
    };
  7. @ChaseFlorell ChaseFlorell revised this gist May 2, 2013. 2 changed files with 10 additions and 13 deletions.
    14 changes: 1 addition & 13 deletions uriSchemeWithHyperlinkFallback.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    (function () {

    // tries to execute the uri:scheme
    function uriSchemeWithHyperlinkFallback(uri, href) {
    var start, end, elapsed;
    @@ -21,14 +19,4 @@
    if (elapsed < 1) {
    document.location = href;
    }
    }



    // `intent` is the class we're using to wire this up. Use whatever you like.
    $('a.intent').on('click', function (event) {
    uriSchemeWithHyperlinkFallback($(this).data('scheme'), $(this).attr('href'));
    // we don't want the default browser behavior kicking in and screwing everything up.
    event.preventDefault();
    });
    })();
    };
    9 changes: 9 additions & 0 deletions x-demo.html
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,14 @@
    <a class="intent"
    href="http://facebook.com/someProfile"
    data-scheme="fb://profile/10000">facebook</a>

    <script>
    // `intent` is the class we're using to wire this up. Use whatever you like.
    $('a.intent').on('click', function (event) {
    uriSchemeWithHyperlinkFallback($(this).data('scheme'), $(this).attr('href'));
    // we don't want the default browser behavior kicking in and screwing everything up.
    event.preventDefault();
    });
    </script>
    </body>
    </html>
  8. @ChaseFlorell ChaseFlorell renamed this gist Mar 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @ChaseFlorell ChaseFlorell created this gist Mar 8, 2013.
    12 changes: 12 additions & 0 deletions demo.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="uriSchemeWithHyperlinkFallback.js"></script>
    </head>
    <body>
    <!-- links will work as expected where javascript is disabled-->
    <a class="intent"
    href="http://facebook.com/someProfile"
    data-scheme="fb://profile/10000">facebook</a>
    </body>
    </html>
    34 changes: 34 additions & 0 deletions uriSchemeWithHyperlinkFallback.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    (function () {

    // tries to execute the uri:scheme
    function uriSchemeWithHyperlinkFallback(uri, href) {
    var start, end, elapsed;

    // start a timer
    start = new Date().getTime();

    // attempt to redirect to the uri:scheme
    // the lovely thing about javascript is that it's single threadded.
    // if this WORKS, it'll stutter for a split second, causing the timer to be off
    document.location = uri;

    // end timer
    end = new Date().getTime();

    elapsed = (end - start);

    // if there's no elapsed time, then the scheme didn't fire, and we head to the url.
    if (elapsed < 1) {
    document.location = href;
    }
    }



    // `intent` is the class we're using to wire this up. Use whatever you like.
    $('a.intent').on('click', function (event) {
    uriSchemeWithHyperlinkFallback($(this).data('scheme'), $(this).attr('href'));
    // we don't want the default browser behavior kicking in and screwing everything up.
    event.preventDefault();
    });
    })();