patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
function (pattern, givenPath) {
    var data         = { "pattern": pattern };
    var fileName     = urlHandler.getFileName(pattern);
    var path         = window.location.pathname;
    path             = (window.location.protocol === "file") ? path.replace("/public/index.html","public/") : path.replace(/\/index\.html/,"/");
    var expectedPath = window.location.protocol+"//"+window.location.host+path+fileName;
    if (givenPath != expectedPath) {
      // make sure to update the iframe because there was a click
      var obj = JSON.stringify({ "event": "patternLab.updatePath", "path": fileName });
      document.getElementById("sg-viewport").contentWindow.postMessage(obj, urlHandler.targetOrigin);
    } else {
      // add to the history
      var addressReplacement = (window.location.protocol == "file:") ? null : window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"?p="+pattern;
      if (history.pushState !== undefined) {
        history.pushState(data, null, addressReplacement);
      }
      document.getElementById("title").innerHTML = "Pattern Lab - "+pattern;
      if (document.getElementById("sg-raw") !== null) {
        document.getElementById("sg-raw").setAttribute("href",urlHandler.getFileName(pattern));
      }
    }
  }
function (pattern, givenPath) {
    var data         = { "pattern": pattern };
    var fileName     = urlHandler.getFileName(pattern);
    var path         = window.location.pathname;
    path             = (window.location.protocol === "file") ? path.replace("/public/index.html","public/") : path.replace(/\/index\.html/,"/");
    var expectedPath = window.location.protocol+"//"+window.location.host+path+fileName;
    if (givenPath != expectedPath) {
      // make sure to update the iframe because there was a click
      var obj = JSON.stringify({ "event": "patternLab.updatePath", "path": fileName });
      document.getElementById("sg-viewport").contentWindow.postMessage(obj, urlHandler.targetOrigin);
    } else {
      // add to the history
      var addressReplacement = (window.location.protocol == "file:") ? null : window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"?p="+pattern;
      if (history.pushState !== undefined) {
        history.pushState(data, null, addressReplacement);
      }
      document.getElementById("title").innerHTML = "Pattern Lab - "+pattern;
      if (document.getElementById("sg-raw") !== null) {
        document.getElementById("sg-raw").setAttribute("href",urlHandler.getFileName(pattern));
      }
    }
  }
function ( pattern , givenPath ) { var data = { "pattern" : pattern } ; var fileName = urlHandler . getFileName ( pattern ) ; var path = window . location . pathname ; path = ( window . location . protocol === "file" ) ? path . replace ( "/public/index.html" , "public/" ) : path . replace ( / \/index\.html / , "/" ) ; var expectedPath = window . location . protocol + "//" + window . location . host + path + fileName ; if ( givenPath != expectedPath ) { // make sure to update the iframe because there was a click var obj = JSON . stringify ( { "event" : "patternLab.updatePath" , "path" : fileName } ) ; document . getElementById ( "sg-viewport" ) . contentWindow . postMessage ( obj , urlHandler . targetOrigin ) ; } else { // add to the history var addressReplacement = ( window . location . protocol == "file:" ) ? null : window . location . protocol + "//" + window . location . host + window . location . pathname . replace ( "index.html" , "" ) + "?p=" + pattern ; if ( history . pushState !== undefined ) { history . pushState ( data , null , addressReplacement ) ; } document . getElementById ( "title" ) . innerHTML = "Pattern Lab - " + pattern ; if ( document . getElementById ( "sg-raw" ) !== null ) { document . getElementById ( "sg-raw" ) . setAttribute ( "href" , urlHandler . getFileName ( pattern ) ) ; } } }
push a pattern onto the current history based on a click
@param  {String}       the shorthand partials syntax for a given pattern
@param  {String}       the path given by the loaded iframe
push a pattern onto the current history based on a click