Access new posts

View Demo

Source


<!doctype html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>Accessing new posts appearing in real time</title>

  <!-- Optimize for mobile -->
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- force latest IE rendering engine -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <!-- muut styling -->
  <link rel="stylesheet" href="https://cdn.muut.com/1/moot.css">

  <!-- Custom CSS -->
  <style>
  body {
    font-family: "myriad pro", tahoma, verdana, arial, sans-serif;
    font-size: 18px; margin: 0; padding: 0;
  }

  .desc {
    font-size: 80%;
    text-align: center;
    color: #999;
    margin: 2em 0;
  }
  </style>

</head>

<body>

  <p class="desc">Look for HTML source code to see the API in action</p>

  <a class="muut m-app-loading" href="https://muut.com/i/goma">Muut forums</a>
  <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="https://cdn.muut.com/1/moot.min.js"></script>

  <script>

  // This function is called when the client is loaded
  muut(function(app) {

    // Called whena a new channel (category) is loaded
    app.page.on('moot', function(thread, is_new) {

      // A new thread was created
      if (is_new) {
        console.log('New thread created', thread)

      }

      // A new reply was created
      thread.on('reply', function(reply) {
        console.log('New reply created', reply)
      })

    })

  })
  </script>

</body>

</html>

View Demo