Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://unpkg.com/@sjmc11/[email protected]/dist/tour.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://unpkg.com/@sjmc11/[email protected]/dist/css/tour.min.css">


<div class="content">
  <h1>TourGuide.JS 0.0.7</h1>
  <button id="start">Start Tour</button>
  <p id="end"><a href="https://github.com/sjmc11/tourguide-js" target="_blank" rel="noopener">https://github.com/sjmc11/tourguide-js</a></p>
  
    <p id="end">official site code<br><a href="https://codepen.io/sjmc11/pen/MWXrVWo" target="_blank" rel="noopener">https://codepen.io/sjmc11/pen/MWXrVWo</a></p>
  
  <table>
    <tbody>
      <tr>
        <td>name</td>
        <td><span id="name"></span></td>
      </tr>
      <tr>
        <td>email</td>
        <td><span id="email"></span></td>
      </tr>
    </tbody>
  </table>
</div>

              
            
!

CSS

              
                html {
  font-size: 10px;
}

body {
  padding: 0;
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.1em;
  line-height: 1.6;
  background-color: #fff;
  color: #000;
  word-wrap : break-word;
  overflow-wrap : break-word;
}



#start {
  font-size: 2rem;
  background: #79c3bf;
  border: none;
  border-radius: 10px;
  padding: 15px;
  cursor: pointer;
  letter-spacing: 0.1em;
  &:hover {
    opacity: 0.7;
  }
}

.content {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding: 5rem;
  max-width: 500px;
  margin: 0 auto;
}

table {
  width: 70%;
  table-spacing: 0;
  
  td {
    padding: 10px 0 5px;
    border-bottom: 1px solid #555;
    &:first-child{
      width: 80px;
    }
  }
}
.c-red {
  color: #f33;
}

              
            
!

JS

              
                const tg = new tourguide.TourGuideClient();
document.querySelector('#start').addEventListener('click', () => {
  tg.start()  
});

tg.onBeforeStepChange(()=>{
  console.log('\n%c-------------------- Step Change --------------------', 'color:red;font-weight:bold;');
  console.log('%cEvent onBeforeStepChange. arrow function this...','background-color:lightyellow;', this);
});

tg.onAfterStepChange(function(){
  console.log('%cEvent onBeforeStepChange. function this...','background-color:lightgreen;', this);
});

tg.onAfterExit(function(){
  console.log('%c The tour has closed ', 'background:#f55; color:#fff;', this);
  // Empty the element after closing
  const tgBody = this.dialog.querySelector('#tg-dialog-body');
  if (tgBody) {
    while(tgBody.lastChild){
      tgBody.removeChild(tgBody.lastChild);
    }
  }
})


// STEP1
const step1Content = `
  <p>Enter your name.</p>
  <input id="step1NameInput" type="text">
  <p id="step1NameInputError" style="color:red;"></p>
  `;
const step1 = {
  title: 'Enter name',
  content: step1Content,
  
  // Enter events
  beforeEnter: (currentStep, nextStep) => {
    console.log('step1 beforeEnter:', currentStep);
    tg.setOptions({
      hidePrev: true
    });
  },
  afterEnter: (currentStep, nextStep) => {
    console.log('step1 afterEnter:', currentStep);
  },
  
  // Leave events
  beforeLeave: (currentStep, nextStep) => {
    console.log('step1 beforeLeave:', currentStep);
    return new Promise((resolve, reject) => {
      const name = document.querySelector('#name'); // get front name element
      const step1NameInput = document.querySelector('#step1NameInput');
      const step1NameInputError = document.querySelector('#step1NameInputError');
      console.log("nameInput", step1NameInput)
      
      if (step1NameInput){
        if (!step1NameInput.value) {
          step1NameInputError.textContent = 'enter name';
          return reject(false);
        }
        name.textContent = step1NameInput.value;
      }
      return resolve(true);
    });
    
  },
  afterLeave: (currentStep, nextStep) => {
    console.log('step1 afterLeave:', currentStep);
  }
}

// STEP2
// create step elements
const step2ContentDiv = document.createElement('div');
const step2ContentP = document.createElement('p');
step2ContentP.textContent = 'Enter your email.';
step2ContentDiv.appendChild(step2ContentP);
const step2ContentInput = document.createElement('input')
step2ContentInput.setAttribute('type', 'email');
step2ContentDiv.appendChild(step2ContentInput);
const step2ContentInputError = document.createElement('p')
step2ContentInputError.setAttribute('style', 'color:red;');
step2ContentDiv.appendChild(step2ContentInputError);

const step2 = {
  title: 'Enter email',
  content: step2ContentDiv,
  
  // Enter events
  beforeEnter: (currentStep, nextStep) => {
    console.log('step2 beforeEnter:', currentStep, nextStep);
    tg.setOptions({
      hidePrev: false
    });
  },
  afterEnter: (currentStep, nextStep) => {
    console.log('step2 afterEnter:', currentStep);
  },
  
  // Leave events
  beforeLeave: (currentStep, nextStep) => {
    console.log('step2 beforeLeave:', currentStep);
    return new Promise((resolve, reject) => {
      const email = document.querySelector('#email'); // get front email element
      const val = step2ContentInput.value;
      step2ContentInputError.textContent = '';
      
      if (val === '') {
        step2ContentInputError.textContent = 'enter email';
        return reject(false);
      }

      email.textContent = val;

      return resolve(true);
    });
  },
  afterLeave: (currentStep, nextStep) => {
    console.log('step2 afterLeave:', currentStep);
  }
}


// STEP3
const step3 = {
  title: 'Finish!',
  target: '#end',
  content: 'Click here for details'
}

// add steps
tg.addSteps([step1, step2, step3])
              
            
!
999px

Console