Pen Settings

HTML

CSS

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

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

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.

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

              
                
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Solid Bookmarks</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
</head>

<body>

  <nav class="navbar" role="navigation" aria-label="main navigation">
    <div class="navbar-brand">
      <a id="add" class="navbar-item" href="#">
      + Create Bookmark
    </a>

      <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
      <span aria-hidden="true"></span>
      <span aria-hidden="true"></span>
      <span aria-hidden="true"></span>
    </a>
    </div>

    <div id="navbarBasicExample" class="navbar-menu">
      <div class="navbar-start">

        <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link">
          About
        </a>

          <div class="navbar-dropdown">

            <a class="navbar-item">
            <a target="_blank" href="https://github.com/melvincarvalho/solid-bookmark/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc">Report an issue</a>
            </a>
          </div>
        </div>
      </div>

      <div class="navbar-end">
        <div class="navbar-item">

          <div class="buttons">
            <a id="register" href="https://solid.inrupt.com/get-a-solid-pod" target="_blank" class="button is-primary">
                     <strong>Sign up</strong>
                     </a>
            <a id="login" class="button is-light">
                     Login
                     </a>
            <a id="logout" class="button is-light" style="display:none">
                     Logout
                     </a>
          </div>

        </div>
      </div>
    </div>
  </nav>

  <section class="section">
    <div class="container">
      <h1 class="title">
        Solid Bookmarks
      </h1>
      <section id="app" style="display:none">
        <hr>
        <a id="user" target="_blank" href="#"></a>
        <hr>
        <section id="showbookmarks">
        <div id="name"></div>
        <hr>
        <div id="bookmarks"></div>
        </section>
        <section id="addbookmarks" style="display:none">
          add bookmark
          <form>
          </form>
        </section>
      </section>
    </div>
  </section>

  <div id="modal" class="modal">
    <div class="modal-background"></div>
    <div class="modal-card">
      <header class="modal-card-head">
        <p class="modal-card-title">Create Bookmark</p>
        <button id="close" class="delete" aria-label="close"></button>
      </header>
      <section class="modal-card-body">
        Create a bookmark
        <form>
          <input id="title" type="text" placeholder="Title">
          <br>
          <input id="uri" type="text" placeholder="Uri">
        </form>
      </section>
      <footer class="modal-card-foot">
        <button id="save" class="button is-success">Save changes</button>
        <button id="cancel" class="button">Cancel</button>
      </footer>
    </div>
  </div>

  <script src="https://melvincarvalho.github.io/helloworld/scripts/jquery.js"></script>
  <script src="https://melvincarvalho.github.io/helloworld/scripts/solid-auth-client.bundle.js"></script>
  <script src="https://melvincarvalho.github.io/helloworld/scripts/rdflib.min.js"></script>
  <script>
    // INIT
    var template = {}
    template.bookmarks = []

    function init () {
      addListeners();
      hamburgerHelper();
      var webId = getQueryStringParam('webid')
      if (webId) {
        template.webId = webId
        renderLogin(webId)
      }
      console.log('webid', template.webId)
    }

    // RENDER FUNCTIONS
    function renderLogin(webId) {
      if (template.webId) webId = template.webId
      console.log('logged in as', webId)
      let logout = document.getElementById("logout");
      let login = document.getElementById("login");
      let register = document.getElementById("register")
      let app = document.getElementById("app");
      logout.style = '';
      register.style.display = "none";
      login.style.display = "none"
      app.style.display = "";
      user.style.display = "";
      user.textContent = webId;
      user.setAttribute("href", webId);
      fetchProfile(webId);
    }

    function renderLogout() {
      let logout = document.getElementById("logout");
      let login = document.getElementById("login");
      let register = document.getElementById("register");
      let app = document.getElementById("app");
      logout.style.display = "none";
      app.style.display = "none";
      login.style.display = "";
      register.style.display = "";
    }

    function renderBookmarks() {
      let bookmarks = document.getElementById("bookmarks");
      bookmarks.innerHTML = ''
      for (var i = 0; i < template.bookmarks.length; i++) {
        let bookmark = template.bookmarks[i]
        bookmarks.insertAdjacentHTML('beforeEnd', "<strong>" + bookmark.title + "</strong>")
        bookmarks.insertAdjacentHTML('beforeEnd', "<br>")
        bookmarks.insertAdjacentHTML('beforeEnd', "<br>")
        bookmarks.insertAdjacentHTML('beforeEnd', "<a target='_blank' href='" + bookmark.recall + "'>" + bookmark.recall + "</a>")
        bookmarks.insertAdjacentHTML('beforeEnd', "<hr>")
      }
    }
    // HANDLERS
    function handleLogin() {
      // login event
      solid.auth.trackSession(session => {
        if (session && session.webId || template && template.webId) {
          renderLogin(session.webId);
        } else {
          renderLogout();
        }
      });
    }
    // Log the user in and out on click
    function addListeners() {
      let login = document.getElementById("login");
      let logout = document.getElementById("logout");
      let close = document.getElementById("close");
      let cancel = document.getElementById("cancel");
      let save = document.getElementById("save");
      // login and logout buttons
      const popupUri = "https://melvincarvalho.github.io/helloworld/popup.html";
      login.addEventListener("click", () => solid.auth.popupLogin({
        popupUri
      }));
      logout.addEventListener("click", () => solid.auth.logout());
      handleLogin();

      add.addEventListener("click", () => {
        document.getElementById('modal').classList.add('is-active')
      })
      close.addEventListener("click", () => {
        document.getElementById('modal').classList.remove('is-active')
      })
      cancel.addEventListener("click", () => {
        document.getElementById('modal').classList.remove('is-active')
      })
      save.addEventListener("click", () => {
        document.getElementById('modal').classList.remove('is-active')
        let id = "#" + Math.random()
        let uri = document.getElementById('uri').value
        let title = document.getElementById('title').value
        let source = template.bookmarkInstance
        const query = ` INSERT DATA {
            <${id}> a <https://www.w3.org/2002/01/bookmark#Bookmark> ;
            <http://purl.org/dc/terms/title>   """${title}""" ;
            <https://www.w3.org/2002/01/bookmark#recall> <${uri}> .
          }`
        // Send a PATCH request to update the source
        console.log("query", query)
        solid.auth.fetch(source, {
          method: 'PATCH',
          headers: { 'Content-Type': 'application/sparql-update' },
          body: query,
          credentials: 'include',
        });


      })



    }
    // HELPERS
    function hamburgerHelper() {
      document.querySelector(".navbar-burger").addEventListener("click", toggleNav);

      function toggleNav() {
        var nav = document.querySelector(".navbar-menu");
        if (nav.className == "navbar-menu") {
          nav.className = "navbar-menu is-active";
        } else {
          nav.className = "navbar-menu";
        }
      }
    }

    function getQueryStringParam(param) {
      var url = window.location.toString();
      url.match(/\?(.+)$/);
      var params = RegExp.$1;
      params = params.split("&");
      var queryStringList = {};
      for (var i = 0; i < params.length; i++) {
        var tmp = params[i].split("=");
        queryStringList[tmp[0]] = unescape(tmp[1]);
      }
      return queryStringList[param];
    }
    // FETCH
    async function fetchProfile(webId) {
      const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/');
      const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#');
      const store = $rdf.graph();
      const fetcher = new $rdf.Fetcher(store);
      // Load the person's data into the store
      await fetcher.load(webId);
      // Display their details
      const name = store.any($rdf.sym(webId), FOAF('name'));
      const img = store.any($rdf.sym(webId), FOAF('img'));
      const publicTypeIndex = store.any($rdf.sym(webId), SOLID('publicTypeIndex'), null, $rdf.sym(webId.split('#')[0]));
      //console.log("publicTypeIndex", publicTypeIndex)
      if (name && name.value) {
        document.getElementById("name").textContent = name.value;
      }
      if (img && img.value) {
        document.getElementById("img").setAttribute("src", img.value);
      }
      if (publicTypeIndex && publicTypeIndex.value) {
        fetchPublicTypeIndex(publicTypeIndex)
      }
    }
    async function fetchPublicTypeIndex(publicTypeIndex) {
      const BOOKMARK = $rdf.Namespace('https://www.w3.org/2002/01/bookmark#');
      const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#');
      const store = $rdf.graph();
      const fetcher = new $rdf.Fetcher(store);
      // Load the person's data into the store
      await fetcher.load(publicTypeIndex);
      // Display their details
      const bookmarkTypeRegistration = store.any(null, SOLID("forClass"), BOOKMARK("Bookmark"))
      console.log("bookmarkTypeRegistration", bookmarkTypeRegistration)
      if (bookmarkTypeRegistration && bookmarkTypeRegistration.value) {
        const bookmarkInstance = store.any(bookmarkTypeRegistration, SOLID("instance"));
        fetchBookmarks(bookmarkInstance)
        template.bookmarkInstance = bookmarkInstance.value
      }
    }
    async function fetchBookmarks(bookmarkInstance) {
      const BOOKMARK = $rdf.Namespace('https://www.w3.org/2002/01/bookmark#');
      const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#');
      const RDF = $rdf.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
      const DC = $rdf.Namespace('http://purl.org/dc/terms/')
      const store = $rdf.graph();
      const fetcher = new $rdf.Fetcher(store)
      // Load the person's data into the store
      console.log("bookmarkInstance", bookmarkInstance)
      await fetcher.load(bookmarkInstance);
      // Display their details
      const bookmarks = store.statementsMatching(null, RDF("type"), BOOKMARK("Bookmark"));
      console.log("Bookmarks", bookmarks);
      if (bookmarks && bookmarks.length) {
        template.bookmarks = []
        for (var i = 0; i < bookmarks.length; i++) {
          let bookmark = bookmarks[i]
          let title = store.any(bookmark.subject, DC('title'))
          let recall = store.any(bookmark.subject, BOOKMARK('recall'))
          template.bookmarks.push({
            "recall": recall.value,
            "title": title.value
          })
          console.log("bookmark " + i, bookmark)
        }
        console.log("template.bookmarks", template.bookmarks)
        renderBookmarks()
      }
      console.log()
    }
    // MAIN
    init()

  </script>

</body>

</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console