mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 20:25:51 +00:00
Use JS shortcut for interactive tutorial breadcrumbs
This commit is contained in:
19
assets/js/interactive-tutorial.js
Normal file
19
assets/js/interactive-tutorial.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Helper functions for interactive tutorials
|
||||||
|
|
||||||
|
function slugify(s) {
|
||||||
|
const unacceptable_chars = /[^A-Za-z0-9._ ]+/
|
||||||
|
const whitespace_regex = /\s+/
|
||||||
|
s = s.replace(unacceptable_chars, "")
|
||||||
|
s = s.replace(whitespace_regex, "_")
|
||||||
|
s = s.toLowerCase()
|
||||||
|
if (!s) {
|
||||||
|
s = "_"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
function complete_step(step_name) {
|
||||||
|
const step_id = slugify(step_name)
|
||||||
|
$(".bc-"+step_id).removeClass("active").addClass("done")
|
||||||
|
$(".bc-"+step_id).next().removeClass("disabled").addClass("active")
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ This tutorial explains how to send a simple XRP Payment using RippleAPI for Java
|
|||||||
<!-- Interactive example use ripple-lib and its prerequisites -->
|
<!-- Interactive example use ripple-lib and its prerequisites -->
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
|
||||||
<script type="application/javascript" src="assets/js/ripple-lib-1.1.2-min.js"></script>
|
<script type="application/javascript" src="assets/js/ripple-lib-1.1.2-min.js"></script>
|
||||||
|
<!-- Helper for interactive tutorial breadcrumbs -->
|
||||||
|
<script type="application/javascript" src="assets/js/interactive-tutorial.js"></script>
|
||||||
|
|
||||||
- This page provides JavaScript examples that use the ripple-lib (RippleAPI) library version 1.1.2. The [RippleAPI Beginners Guide](get-started-with-rippleapi-for-javascript.html) describes how to get started using RippleAPI to access XRP Ledger data from JavaScript.
|
- This page provides JavaScript examples that use the ripple-lib (RippleAPI) library version 1.1.2. The [RippleAPI Beginners Guide](get-started-with-rippleapi-for-javascript.html) describes how to get started using RippleAPI to access XRP Ledger data from JavaScript.
|
||||||
|
|
||||||
@@ -67,11 +69,7 @@ $(document).ready( () => {
|
|||||||
|
|
||||||
$("#populate-creds-status").text("Populated this page's examples with these credentials.")
|
$("#populate-creds-status").text("Populated this page's examples with these credentials.")
|
||||||
|
|
||||||
// Update all breadcrumbs
|
complete_step("Generate")
|
||||||
$(".bc-generate").removeClass("active")
|
|
||||||
$(".bc-generate").addClass("done")
|
|
||||||
$(".bc-connect").removeClass("disabled")
|
|
||||||
$(".bc-connect").addClass("active")
|
|
||||||
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
@@ -126,11 +124,8 @@ api.on('connected', () => {
|
|||||||
$("#connect-button").prop("disabled", true)
|
$("#connect-button").prop("disabled", true)
|
||||||
$("#loader-{{n.current}}").hide()
|
$("#loader-{{n.current}}").hide()
|
||||||
|
|
||||||
// Update all breadcrumbs & active next step
|
// Update breadcrumbs & active next step
|
||||||
$(".bc-connect").removeClass("active")
|
complete_step("Connect")
|
||||||
$(".bc-connect").addClass("done")
|
|
||||||
$(".bc-prepare").removeClass("disabled")
|
|
||||||
$(".bc-prepare").addClass("active")
|
|
||||||
$("#interactive-prepare button").prop("disabled", false)
|
$("#interactive-prepare button").prop("disabled", false)
|
||||||
$("#interactive-prepare button").prop("title", "")
|
$("#interactive-prepare button").prop("title", "")
|
||||||
})
|
})
|
||||||
@@ -226,11 +221,8 @@ txJSON = doPrepare()
|
|||||||
maxLedgerVersion + "</div>"
|
maxLedgerVersion + "</div>"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update all breadcrumbs & active next step
|
// Update breadcrumbs & active next step
|
||||||
$(".bc-prepare").removeClass("active")
|
complete_step("Prepare")
|
||||||
$(".bc-prepare").addClass("done")
|
|
||||||
$(".bc-sign").removeClass("disabled")
|
|
||||||
$(".bc-sign").addClass("active")
|
|
||||||
$("#interactive-sign button").prop("disabled", false)
|
$("#interactive-sign button").prop("disabled", false)
|
||||||
$("#interactive-sign button").prop("title", "")
|
$("#interactive-sign button").prop("title", "")
|
||||||
})
|
})
|
||||||
@@ -284,10 +276,7 @@ The signing API also returns the transaction's ID, or identifying hash, which yo
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Update all breadcrumbs & activate next step
|
// Update all breadcrumbs & activate next step
|
||||||
$(".bc-sign").removeClass("active")
|
complete_step("Sign")
|
||||||
$(".bc-sign").addClass("done")
|
|
||||||
$(".bc-submit").removeClass("disabled")
|
|
||||||
$(".bc-submit").addClass("active")
|
|
||||||
$("#interactive-submit button").prop("disabled", false)
|
$("#interactive-submit button").prop("disabled", false)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -356,11 +345,8 @@ See the full list of [transaction results](transaction-results.html) for more po
|
|||||||
"</div>"
|
"</div>"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update all breadcrumbs & active next step
|
// Update breadcrumbs & active next step
|
||||||
$(".bc-submit").removeClass("active")
|
complete_step("Submit")
|
||||||
$(".bc-submit").addClass("done")
|
|
||||||
$(".bc-wait").removeClass("disabled")
|
|
||||||
$(".bc-wait").addClass("active")
|
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
$("#loader-{{n.current}}").hide()
|
$("#loader-{{n.current}}").hide()
|
||||||
@@ -408,10 +394,7 @@ api.on('ledger', ledger => {
|
|||||||
|
|
||||||
if ( $(".breadcrumb-item.bc-wait").hasClass("active") ) {
|
if ( $(".breadcrumb-item.bc-wait").hasClass("active") ) {
|
||||||
// Advance to "Check" as soon as we see a ledger close
|
// Advance to "Check" as soon as we see a ledger close
|
||||||
$(".breadcrumb-item.bc-wait").removeClass("active")
|
complete_step("Wait")
|
||||||
$(".breadcrumb-item.bc-wait").addClass("done")
|
|
||||||
$(".breadcrumb-item.bc-check").removeClass("disabled")
|
|
||||||
$(".breadcrumb-item.bc-check").addClass("active")
|
|
||||||
$("#get-tx-button").prop("disabled", false)
|
$("#get-tx-button").prop("disabled", false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -465,8 +448,7 @@ The RippleAPI `getTransaction()` method only returns success if the transaction
|
|||||||
"</pre></code></div>"
|
"</pre></code></div>"
|
||||||
)
|
)
|
||||||
|
|
||||||
$(".bc-check").removeClass("active")
|
complete_step("Check")
|
||||||
$(".bc-check").addClass("done")
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
$("#get-tx-output").text("Couldn't get transaction outcome:" + error)
|
$("#get-tx-output").text("Couldn't get transaction outcome:" + error)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user