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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="container">
  <div class="quote-box">
    <p id="js_quote_text"></p>
    <p id="js_quote_title" class="right"></p>
  <div class="ctas">
    <button id="js_tweet"><i class="fa fa-twitter" aria-hidden="true"></i>
</button>
    <button id="js_generate_quote">New Quote</button>
  </div>
  </div>
</div>










<!--<div class="container-fluid">
  <div class="row">
    <div class="col-md-12 text-center">
      <h3 id="js_quote_text">Your quote here...</h3><br/>
      <h4 id="js_quote_title">Quote title...</h4>
    </div>
  </div>
  
  <div class="row">
    <div class="col-md-6 text-right">
      <button class="btn btn-primary btn-sm" id="js_generate_quote">Random quote</button>
    </div>
    <div class="col-md-6">
      <button id="js_tweet" class="btn btn-sm btn-primary">Tweet this quote</button>
    </div>
  </div>
</div>

-->
            
          
!
            
              body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

.right {
  text-align: right;
}

.container {
  height: 100%;
  width: 100%;
  background-color: #b7d2ff;
  display: flex;
  justify-content: center;
  align-items: center;
  
  .quote-box {
    width: 50%;
    background-color: red;
    background-color: white;
    border-radius: 20px;
    padding: 20px;
    font-size: 20px;
    color: #b7d2ff;
    
    .ctas {
      display: flex;
      justify-content: space-between;
      
      button {
        font-size: 17px;
        background-color: #b7d2ff;
        color: white;
        border: none;
        border-radius: 10px;
        padding: 10px 20px;
        outline: none;
      }
    }
  }
}
            
          
!
            
              var LocalQuotesFetchingSource = function() {
  var quotes = [
    {
      content: 'This is a content',
      title: 'Author'
    },
    {
      content: 'This is another content',
      title: 'Some other author'
    }
  ];
    
  this.generateRandomQuote = function() {
    var quote = quotes[this._randomIndex()];
    $("#js_quote_text").text(quote.content);
    $("#js_quote_title").text(quote.title);
  };
  
  this._randomIndex = function() {
    return Math.floor(Math.random()*quotes.length);
  };
}

var ForisMaticQuoteFetchingSource = function() {
  this.generateRandomQuote = function() {
    this._fetchQuoteFromApi();
  };
  
  this._fetchQuoteFromApi = function() {
    $.ajax({
      type: "GET",
      url: "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=",
      success: function(data) {
        var quoteContent = $(data[0].content).text();
        var quoteTitle = data[0].title;
        $("#js_quote_text").text(quoteContent);
        $("#js_quote_title").text(quoteTitle);
      },
      cache: false
    });
  }
}

var QuotesGenerator = function(quotesSource) {
  this.quotesSource = quotesSource;
  this.getQuote = function() {
    this.quotesSource.generateRandomQuote();
  }
}

var quoteGen = new QuotesGenerator(new ForisMaticQuoteFetchingSource());

$(document).ready(init);

function init() {
  generateAndPresentQuote();
  bindEventListeners();
};

function bindEventListeners() {
  $("#js_generate_quote").on("click", generateAndPresentQuote);
  $("#js_tweet").on("click", tweetCurrentQuote);
};

function generateAndPresentQuote() {
  quoteGen.getQuote();
};

function tweetCurrentQuote() {
  var currentQuote = $("#js_quote_text").text();
  var twtLink = 'https://twitter.com/intent/tweet?text=' + currentQuote;
  window.open(twtLink, '_blank');
};
            
          
!
999px
Loading ..................

Console