cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

            
              body {
  margin: 0;
  font-size: 14px;
  font-family: 'Open Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  width: 100%;
  max-width: 600px;
  margin: 100px auto;
  width: 80%;
  
  &__title {
    display: block;
    max-width: 600px;
    width: 80%;
    margin: 0 auto 20px;
    padding: 10px;
    box-sizing: border-box;
    color: #212121;
    font-size: 18px;
    font-weight: 600;
    line-height: 1px;
  }
}

.form {
  display: flex;
  flex-direction: row;
  max-width: 600px;
  width: 80%;
  margin: 0 auto;
}

.input {
  outline: none;
  background: #FFFFFF;
  width: 100%;
  height: 40px;
  border: 1px solid #EEEEEE;
  border-radius: 2px;
  margin: 0 10px;
  padding: 0 20px;
  box-sizing: border-box;
  
  &:focus {
    border-color: #2B87DA;
  }
  
  &--error {
    border-color: #EF5555;
  }
}

.textarea {
  outline: none;
  display: block;
  background: #FFFFFF;
  width: 100%;
  height: 200px;
  border: 1px solid #EEEEEE;
  border-radius: 2px;
  margin: 0 10px;
  padding: 20px;
  box-sizing: border-box;
  line-height: 18px;
  
  &:focus {
    border-color: #2B87DA;
  }
}

.button {
  outline: none;
  background: #2B87DA;
  height: 40px;
  border: 0;
  border-radius: 2px;
  margin: 0 10px;
  padding: 0 20px;
  box-sizing: border-box;
  color: #FFFFFF;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}

.results {
  display: flex;
  flex-direction: row;
  max-width: 600px;
  width: 80%;
  margin: 20px auto 0;
}

.examples {
  max-width: 600px;
  width: 80%;
  border-top: 1px solid #EEEEEE;
  margin: 40px auto 0;
  padding: 40px 10px 0;
  box-sizing: border-box;
  
  &__title {
    margin: 0 0 10px;
    color: #444444;
    line-height: 1;
    font-size: 14px;
    font-weight: 600;
  }
  
  &__content {
    padding: 10px 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  
  &__item {
    position: relative;
    display: inline-block;
    width: 200px;
    height: 120px;
    border: 1px solid #EEEEEE;
    border-radius: 2px;
    margin: 0 10px;
    overflow: hidden;
    
    &:before {
      content: '';
      z-index: 1;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background: transparent;
      width: 100%;
      height: 100%;
    }
    
    &:first-child {
      margin-left: 0;
    }
    
    &:last-child {
      margin-right: 0;
    }
    
    iframe {
      width: 400%;
      height: 400%;
      border: 0;
      transform: scale(0.25);
      transform-origin: top left;
    }
  }
}
            
          
!
            
              console.clear();

const { Component, PropTypes } = React;
const { render } = ReactDOM;

class App extends Component {
  constructor() {
    super();
    
    this.state = {
      cssCode: '',
      error: false,
      examples: [
        '//s.codepen.io/andytran/debug/dNPMOB',
        '//s.codepen.io/andytran/debug/MJYaRw',
        '//s.codepen.io/andytran/debug/ggMYod',
        '//s.codepen.io/andytran/debug/dNGJJN',
        '//s.codepen.io/andytran/debug/vgNjjd',
        '//s.codepen.io/andytran/debug/MJKOqB',
      ],
      htmlCode: '',
      url: '',
      jsCode: '',
      request: false,
    }
    
    this._handleAjaxRequest = this._handleAjaxRequest.bind(this);
    this._onChange = this._onChange.bind(this);
    this._onClick = this._onClick.bind(this);
    this._onKeyDown = this._onKeyDown.bind(this);
  }
  
  _handleAjaxRequest(ext) {
    const self = this;
    this.setState({ 
      error: false,
      request: true,
    });
    
    $.ajax({
      url: `${this.state.url}.${ext}`,
      success: (data) => {
        if (ext === 'css') {
          return self.setState({ 
            cssCode: data ? `<style>${data}</style>` : '',
            request: false,
          });
        } else if (ext === 'html') {
          return self.setState({ 
            htmlCode: data,
            request: false,
          });
        } else if (ext === 'js') {
          return self.setState({ 
            jsCode: '<scr' + 'ipt>' + data + '</scr' + 'ipt>',
            request: false,
          });
        }
        
        return false;
      },
      error: () => {
        self.setState({ 
          cssCode: '',
          error: true,
          htmlCode: '',
          jsCode: '',
          request: false,
        });
      },
      type: 'get',
    });
  }
  
  _onChange(event) {
    const protocol = event.target.value.substring(0, 5);
    let url = event.target.value.substring(5);
    
    if (window.location.protocol === 'https:') {
      url = event.target.value;
    }
    
    if (protocol === 'http:') {
      url = `https:${url}`;
    }
    
    this.setState({ 
      cssCode: '',
      htmlCode: '',
      url: url || event.target.value,
      jsCode: '',
    });
  }
  
  _onClick(event) {
    event.preventDefault();
    
    this._handleAjaxRequest('css');
    
    this._handleAjaxRequest('html');
    
    this._handleAjaxRequest('js');
  }
  
  _onKeyDown(event) {
    if (event.keyCode === 13) {    
      event.preventDefault();

      this._handleAjaxRequest('css');

      this._handleAjaxRequest('html');

      this._handleAjaxRequest('js');
    }
  }
  
  _renderButton() {
    const { cssCode, htmlCode, jsCode } = this.state;
    
    const clipboard = new Clipboard('#copy');
    
    if (!cssCode || !htmlCode || !jsCode) {
      return (
        <button 
          className="button" 
          onClick={this._onClick}
          type="button"
          disabled={this.state.request}
        >
          Generate
        </button>
      );
    }
    
    return (
      <button 
        className="button"
        data-clipboard-target="#results"
        id="copy"
        onClick={(e) => e.preventDefault()}
        type="button"
      >
        Copy Code
      </button>
    );
  }
  
  _renderCode() {
    const { cssCode, htmlCode, jsCode } = this.state;
    
    if (!cssCode || !htmlCode || !jsCode) {
      return '';
    }
    
    return cssCode.replace(/\s+/g, ' ') + htmlCode.replace(/\s+/g, ' ') + jsCode.replace(/\s+/g, ' ')
  }
  
  _renderExample(url, i) {
    return (
      <a 
        className="examples__item" 
        href={url} 
        target="_blank"
      >
        <iframe src={url} />
      </a>
    );
  }
  
  render() {
    return (
      <div className="app">
        <h1 className="app__title">Code Module Generator</h1>
        
        <form className="form">
          <input 
            className={`input${this.state.error ? ' input--error' : ''}`}
            name="id" 
            onChange={this._onChange}
            onKeyDown={this._onKeyDown}
            placeholder="CodePen URL (Ex. https://codepen.io/andytran/pen/dNPMOB)" 
            ref={(input) => { this.textInput = input; }}
            required
            type="text" 
          />
          {this._renderButton()}
        </form>
        <div className="results">
          <textarea 
            className="textarea"
            id="results"
            value={this._renderCode()}
            disabled={this.state.request}
          />
        </div>
        <div className="examples">
          <h1 className="examples__title">Works with Divi Code Module</h1>
          <div className="examples__content">
            {this.state.examples.map(this._renderExample)}
          </div>
        </div>
      </div>
    );
  }
}

render(<App />, document.getElementById('root'));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console