HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<container class="c">
<!-- top element -->
<container class="ctop">
<container class="fixh">
<container class="col2parent">
<h3 class="child1">
Template Embedded Signing</h3>
<div class="child2">
<div id="login">
<a id="btnOauth" class="btn btn-primary" type="button" role="button">
Login with DocuSign</a>
<p>
Use your DocuSign <b>Developer Account.</b><br/>Don't have one?
<a href="https://go.docusign.com/o/sandbox/?utm_campaign=GBL_XX_DEV_NEW_2208_ExternalProgrammingTools&utm_medium=display&utm_source=jsfiddle" target="_blank">Free signup!</a>
</p>
</div>
<div id="loggedin" class="hide">
<p id="lname" class="lname mb-0"></p>
<p id="lemail" class="mb-0"></p>
<p id="laccount" class="mb-0"></p>
<p id="laccountname" class="mb-1"></p>
<p id="saccount" class="hide">
<a data-mdb-toggle="modal"
data-mdb-target="#switchAccountModal">
Switch Account</a>
</p>
</div>
</div>
</container>
<noscript>
<h1>Problem! This page <i>requires</i> JavaScript support.
Please update your browser settings.
</h1>
</noscript>
<p>
This example shows how a DocuSign customer can login and send a basic envelope. <br />
Then sign the envelope with an embedded signing ceremony.</p>
<section id="spinner" class="hide">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</section>
<div id="doit" class="hide mb-3">
<a id="btnDoit" class="btn btn-primary" type="button" role="button">
Send and Sign an Envelope</a>
</div>
<p><small> A template is used to create the envelope. The template includes checkboxes and text fields. Also, the app adds metadata
to the envelope object. And the signer is updated to be an embedded signer.
DocuSign recommends using a template when you can. The DocuSign webapp is used to create and manage templates. It's easier to make changes via the webapp than to update an API application.
</small></p>
<p><small>
This example enables the user to switch between their accounts. It remembers the last account used by storing the account ID in the browser's local storage. When the user logs in, the application checks that CORS is enabled for this application on the user's account.
</small></p>
<p><small>
If the signer does not have a DocuSign account, then either use a PowerForm, or JWT authentication with a server-based application.
This example uses Implicit Grant authentication and CORS. Therefore the user must have their own login with a DocuSign account.
</small></p>
</container>
</container>
<!-- The resizer -->
<div class="resizer" id="dragMe"></div>
<!-- Right element -->
<container class="cbottom">
<container class="fixh">
<h3>
Log
</h3>
<p id="log">
You can adjust the height of the sections.
</p>
<div id="msg">
</div>
</container>
</container>
</container>
<!-- Switch account modal -->
<div class="modal fade" id="switchAccountModal" tabindex="-1" aria-labelledby="Switch Account" aria-hidden="true">
<div class="modal-dialog modal-l modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Select an Account</h4>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body accountModal-body">
</div>
</div>
</div>
</div>
html,
body {
height: 100%;
margin: 0;
}
container.c {
display: flex;
flex: 1;
flex-direction: column;
border: 1px solid #cbd5e0;
height: 100%;
width: 100%;
}
container.ctop {
display: flex;
height: 25rem;
padding: 1em;
overflow-y: scroll;
}
container.cbottom {
display: flex;
flex: 1;
padding: 1em;
overflow-y: scroll;
}
container.fixh {
width: 100%;
}
container.col2parent {
display: flex;
flex-direction: row;
}
.child1 {
width: 50%;
}
.child2 {
width: 50%;
}
div.resizer {
width: 100%;
cursor: row-resize;
height: 3px;
background-color: #cbd5e0;
}
pre {
text-align: left;
background-color: aliceblue;
font-size: smaller;
margin: 15px;
}
.panel {
margin: 50px 75px;
}
.hide {
display: none;
}
#lname {font-weight: 600;}
#lemail, #laccount, #laccountname {font-size: 75%;}
#saccount a {
font-size: 85%;
color: blue;
cursor: default;
}
.accountRow {
border-bottom-style: solid;
border-bottom-color: #f2f1f1;
height: 3em;
position: relative
}
.accountRowLast {
border-bottom-style: none;
}
.accountRow:hover {
background-color: #f2f1f1;
}
.accountRow p {
margin: 0;
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
padding-left: 1em;
cursor: default;
}
.accountModal-body {padding: 0;}
/* From http://tobiasahlin.com/spinkit/ */
.spinner {
margin: auto;
width: 150px;
height: 140px;
text-align: center;
font-size: 10px;
}
.spinner>div {
background-color: blueviolet;
height: 100%;
width: 6px;
display: inline-block;
-webkit-animation: sk-stretchdelay 1.2s infinite ease-in-out;
animation: sk-stretchdelay 1.2s infinite ease-in-out;
}
.spinner .rect2 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.spinner .rect3 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.spinner .rect4 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.spinner .rect5 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
@-webkit-keyframes sk-stretchdelay {
0%,
40%,
100% {
-webkit-transform: scaleY(0.4)
}
20% {
-webkit-transform: scaleY(1.0)
}
}
@keyframes sk-stretchdelay {
0%,
40%,
100% {
transform: scaleY(0.4);
-webkit-transform: scaleY(0.4);
}
20% {
transform: scaleY(1.0);
-webkit-transform: scaleY(1.0);
}
}
// Copyright © 2022 DocuSign, Inc.
// License: MIT Open Source https://opensource.org/licenses/MIT
import {
CallApi,
ImplicitGrant,
UserInfo
// View the source at https://codepen.io/docusign/pen/LYBKqxb
} from "https://codepen.io/docusign/pen/LYBKqxb.js"
import {
msg,
htmlMsg,
adjustRows,
errMsg,
workingUpdate,
usingHttps,
getStoredAccountId,
setStoredAccountId,
//switchAccountsModal
// View the source at https://codepen.io/docusign/pen/QWBXYzX
} from "https://codepen.io/docusign/pen/QWBXYzX.js";
// View the source at https://codepen.io/docusign/pen/OJoLNvQ
import { CheckTemplates } from "https://codepen.io/docusign/pen/OJoLNvQ.js";
$(function () {
// Set basic variables
const dsReturnUrl = "https://docusign.github.io/jsfiddleDsResponse.html";
const logLevel = 0; // 0 is terse; 9 is verbose
let signingCeremonyWindow = null;
let accountName, accountId, accountExternalId,
accountBaseUrl, accountIsDefault, corsError; // current account info
// Example settings
let templates = [
{
url: "https://docusign.github.io/examples/templates/Anchor_text_with_checkboxes_v2",
name: "DevCenter example: Anchor text with checkboxes v2",
description:
"This DevCenter example template includes one PDF file with anchor text. Checkboxes are grouped to require that exactly one of the boxes is included. The template includes text fields and envelope metadata.",
templateId: null
}
];
debugger; // uncomment with debugger open to find the right JS file.
/*
* The doit function is the example that is triggered by the
* button. The user is already logged in (we have an access token).
*/
let doit = async function doitf(event) {
$("#doit").addClass("hide");
if (!checkToken()) {
// Check that we have a valid token
return;
}
workingUpdate(true);
const signer = {
name: data.userInfo.name,
email: data.userInfo.email,
clientUserId: 1000
};
const envelopeId = await createEnvelope(signer);
if (envelopeId) {
msg(`Envelope ${envelopeId} created.`);
await embeddedSigningCeremony({
envelopeId: envelopeId,
signer: signer
});
}
$("#doit").removeClass("hide");
workingUpdate(false);
};
doit = doit.bind(this);
/*
* Create the envelope from a template
* on the DocuSign platform
*/
async function createEnvelope({ name, email, clientUserId }) {
const req = {
status: "sent",
compositeTemplates: [
{
compositeTemplateId: "1",
serverTemplates: [
{
sequence: "1",
templateId: templates[0].templateId
}
],
inlineTemplates: [
{
sequence: "1",
customFields: {
listCustomFields: [
{
name: "Envelope list custom field 1",
show: "true",
value: "value 5"
}
]
},
recipients: {
signers: [
{
email: email,
name: name,
clientUserId: clientUserId,
roleName: "Signer1",
recipientId: "1",
customFields: [
"field1: value 1",
"field2: value 2"
]
}
]
}
}
]
}
]
};
// Make the create envelope API call
msg(`Creating envelope...`);
const apiMethod = `/accounts/${accountId}/envelopes`;
const httpMethod = "POST";
const results = await data.callApi.callApiJson({
apiMethod: apiMethod,
httpMethod: httpMethod,
req: req
});
if (results === false) {
return false;
}
if (logLevel > 0) {
htmlMsg(
`<p>Envelope created. Response:</p><p><pre><code>${JSON.stringify(
results,
null,
4
)}</code></pre></p>`
);
}
return results.envelopeId;
}
/*
* Create an embedded signing ceremony, open a new tab with it
*/
async function embeddedSigningCeremony({ envelopeId, signer }) {
const req = {
returnUrl: dsReturnUrl,
authenticationMethod: "None",
clientUserId: signer.clientUserId,
email: signer.email,
userName: signer.name
};
// Make the API call
const apiMethod = `/accounts/${accountId}/envelopes/${envelopeId}/views/recipient`;
const httpMethod = "POST";
const results = await data.callApi.callApiJson({
apiMethod: apiMethod,
httpMethod: httpMethod,
req: req
});
if (results === false) {
return false;
}
if (logLevel > 5) {
htmlMsg(
`<p>Embedded Signing Ceremony created. Response:</p><p><pre><code>${JSON.stringify(
results,
null,
4
)}</code></pre></p>`
);
}
msg(`Displaying signing ceremony...`);
signingCeremonyWindow = window.open(results.url, "_blank");
if(!signingCeremonyWindow || signingCeremonyWindow.closed ||
typeof signingCeremonyWindow.closed=='undefined') {
// popup blocked
alert ("Please enable the popup window signing ceremony");
}
signingCeremonyWindow.focus();
return true;
}
/*
* signingCeremonyEnded
* After the signing ceremony ends (in its own tab),
* the browser tab is redirected to the returnUrl, defined
* in constant dsReturnUrl, above.
* Source:
* https://github.com/docusign/docusign.github.io/blob/master/jsfiddleDsResponse.html
*
* That page runs Javascript to send a message via window.postMessage.
* The message is tagged with source `dsResponse`.
* The function messageListener (in mainline section) receives and
* dispatches the different types of incoming messages.
* When a dsResponse message is received, this function is called.
*/
function signingCeremonyEnded(data) {
if (data.source !== "dsResponse") {
return; // Sanity check
}
signingCeremonyWindow.close(); // close the browser tab
const href = data.href; // "http://localhost:3000/?event=signing_complete"
const sections = href.split("?");
const hasEvents = sections.length === 2;
const qps = hasEvents ? sections[1].split("&") : [];
if (!hasEvents) {
errMsg(`Unexpected signing ceremony response: ${data.href}.`);
return;
}
let msg = `<p><b>Signing Ceremony Response</b><br/>`;
msg += `<small>Information Security tip: do not make business decisions based on this data since they can be spoofed. Instead, use the API.</small>`;
qps.forEach((i) => {
const parts = i.split("=");
msg += `<br/>Query parameter <b>${parts[0]} = "${parts[1]}"</b>`;
});
msg += "</p>";
htmlMsg(msg);
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/* Checks that the access token is still good.
* Prompts for login if not
*/
function checkToken() {
if (data.implicitGrant.checkToken()) {
// ok
return true;
} else {
// not ok
$("#login").removeClass("hide");
$("#doit").addClass("hide");
// reset everything
msg("Please login");
}
}
/*
* Receives and dispatches incoming messages
*/
let messageListener = async function messageListenerf(event) {
if (!event.data) {
return;
}
const source = event.data.source;
if (source === "dsResponse") {
signingCeremonyEnded(event.data);
return;
}
if (source === "oauthResponse" && data.implicitGrant) {
await implicitGrantMsg(event.data);
return;
}
};
messageListener = messageListener.bind(this);
/*
* Process incoming implicit grant response
*/
async function implicitGrantMsg(eventData) {
const oAuthResponse = data.implicitGrant.handleMessage(eventData);
if (oAuthResponse === "ok") {
await completeLogin()
} else if (oAuthResponse === "error") {
$("#login").removeClass("hide");
const errHtml = `<p class="text-danger">${data.implicitGrant.errMsg}</p>`;
htmlMsg(errHtml);
}
}
/*
* Complete login process including
* Get user information
* Set up CallApi object
* Get templates set
* update the user
*/
async function completeLogin() {
data.userInfo = new UserInfo({
accessToken: data.implicitGrant.accessToken,
workingUpdateF: workingUpdate
});
let ok = await data.userInfo.getUserInfo();
corsAccountReport();
ok = ok && await setAccountId(getStoredAccountId());
if (!ok) {
// Did not complete the login or templates issue
$("#login").removeClass("hide");
if (data.userInfo.errMsg) {
const errHtml = `<p class="text-danger">${data.userInfo.errMsg}</p>`;
htmlMsg(errHtml);
}
}
return ok
}
/*
* corsAccountReport -- report on the user's accounts/cors status
*/
function corsAccountReport(){
let corsErr = data.userInfo.accounts.find(a => a.corsError);
corsErr = !!corsErr;
if (!corsErr) {return} // EARLY RETURN
htmlMsg(`<h5>Your Accounts and CORS Access</h5>`);
data.userInfo.accounts.forEach(account => {
const aId = account.corsError ? `<b>CORS Error</b>` :
`#${account.accountExternalId}`;
htmlMsg(`<p class="mb-0">${account.accountName} (${aId})</p>`)
})
if (corsErr) {
errMsg(`One or more of your accounts has not enabled CORS for this application`);
htmlMsg(`<p class="mb-0">To enable CORS, your account administer will use the
<b>CORS</b> page of the eSignature Settings web app.
<a href="https://developers.docusign.com/platform/single-page-applications-cors/enable-disable-cors/" target="_blank">Documentation.</a></p>
<p class="mb-0"><small>Note: if this application is not yet in production, then the problem could also be caused by an app configuration issue:</small></p>
<ul><small>
<li>The domain where the script is hosted is not one of the allowed origins for the app.</li>
<li>The request did not use one of the allowed HTTP methods for the app.</li>
<li>The cors scope was not specified during authentication.</li>
<li>The request did not include an OAuth access token.</li>
<li>The request is not using eSignature REST API v2.1.</li>
<li>The API endpoint path did not include /accounts/{account_id}.</li>
</ul></small>`);
}
}
/*
* setAccountId(accountId)
* If the accountId is null then use the account server's default.
* Also:
* 1. Check that the user has access to the account and cors is on
* for this app.
* 2. Update the account-related settings
* 3. Store the account as the user's default in the browser storage
* 4. Update the callApi and checkTemplates objects
*
* RETURNS ok
*/
async function setAccountId(accountIdArg) {
// if the accountId is null then use the account server's default
function useDefault() {
const account = data.userInfo.accounts[data.userInfo.defaultAccountIndex];
({ accountName, accountId, accountExternalId, accountBaseUrl,
accountIsDefault, corsError } = account);
}
$("#doit").addClass("hide");
let ok = true;
// 1. Check that the user has access to the account.
// 2. Update the account-related settings
if (accountIdArg) {
const account = data.userInfo.accounts.find(a => a.accountId === accountIdArg);
if (account) {
// user has access to the desired account
({ accountName, accountId, accountExternalId, accountBaseUrl,
accountIsDefault, corsError } = account);
} else {
useDefault();
}
} else {
// No accountId parameter -- use user's default
useDefault();
}
// Display the current user and account info
$("#lname").text(data.userInfo.name);
$("#lemail").text(data.userInfo.email);
let aid = `Account #${accountExternalId}`;
if (accountIsDefault) {aid += ` (Default)`}
$("#laccount").text(aid);
$("#laccountname").text(accountName);
if (data.userInfo.accounts.length > 1) {
$("#saccount").removeClass("hide");
}
$("#loggedin").removeClass("hide");
if (corsError) {
errMsg(`Error: this account (${accountName}) has not enabled CORS for this application. Please switch accounts or login again.`);
return false; // EARLY RETURN
}
// 3. Store the account as the user's default in the browser storage
setStoredAccountId(accountId);
// 4. Update the callApi and checkTemplates objects
data.callApi = new CallApi({
accessToken: data.implicitGrant.accessToken,
apiBaseUrl: accountBaseUrl
});
data.checkTemplates = new CheckTemplates({
callApi: data.callApi,
accountId: accountId
});
msg('Checking templates...');
templates = await data.checkTemplates.check(templates);
if (data.checkTemplates.msg) {
msg(data.checkTemplates.msg)
}
if (data.checkTemplates.errMsg) {
errMsg(data.checkTemplates.errMsg)
ok = false;
}
if (ok) {
$("#doit").removeClass("hide");
}
msg('done.'); // done with templates
return ok;
}
/*
* Login button was clicked
*/
let login = async function loginf(event) {
$("#login").addClass("hide");
await data.implicitGrant.login();
};
login = login.bind(this);
/*
* Switch Accounts was clicked
* Displays the modal and processes clicks using the supplied
* callback function
*/
let switchAccountsButton = function(event) {
const accounts = data.userInfo.accounts;
// Only use accounts that include CORS access
const accountsList = accounts.filter (
a => a.accountExternalId && a.accountId !== accountId);
const modalEl = $("#switchAccountModal");
const bodyEl = modalEl.find(".modal-body");
bodyEl.empty();
accountsList.forEach((a, i) => {
bodyEl.append(`
<div class="accountRow ${i < (accountsList.length - 1) ? "": "accountRowLast"}"
data-accountId="${a.accountId}">
<p>
${a.accountName} - ${a.accountExternalId}
${a.accountIsDefault ? "(Default)":""}
</p>
</div>`)
});
}
switchAccountsButton = switchAccountsButton.bind(this);
/**
*
*/
let accountClicked = async function accountClickedFunc(event) {
let target = event.target;
if (target.nodeName === 'P') {
target = $(target).parent()[0];
}
const newAccountId = $(target).attr("data-accountId");
$("#switchAccountModal").modal('hide');
await setAccountId(newAccountId);
}
accountClicked = accountClicked.bind(this);
// Mainline
let data = {
implicitGrant: null,
userInfo: null,
callApi: null,
checkTemplates: null,
};
// The mainline
if (usingHttps()) {
adjustRows();
data.implicitGrant = new ImplicitGrant({
workingUpdateF: workingUpdate
});
window.addEventListener("message", messageListener);
$("#btnOauth").click(login);
$("#btnDoit").click(doit);
$("#saccount a").click(switchAccountsButton);
$("#switchAccountModal .modal-body").click(accountClicked);
}
});
Also see: Tab Triggers