-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatternlab-viewer.min.js
More file actions
1 lines (1 loc) · 27.8 KB
/
patternlab-viewer.min.js
File metadata and controls
1 lines (1 loc) · 27.8 KB
1
function receiveIframeMessage(e){if("file:"==window.location.protocol||e.origin===window.location.protocol+"//"+window.location.host){var t,n={};try{n="string"!=typeof e.data?e.data:JSON.parse(e.data)}catch(a){}if(void 0!==n.event&&"patternLab.updatePath"==n.event)if(void 0!==patternData.patternPartial){var i=/(patterns|snapshots)\/(.*)$/;t=window.location.protocol+"//"+window.location.host+window.location.pathname.replace(i,"")+n.path+"?"+Date.now(),window.location.replace(t)}else t=window.location.protocol+"//"+window.location.host+window.location.pathname.replace("styleguide/html/styleguide.html","")+n.path+"?"+Date.now(),window.location.replace(t);else void 0!==n.event&&"patternLab.reload"==n.event&&window.location.reload()}}!function(e,t,n){function a(e){return e}function i(e){return decodeURIComponent(e.replace(o," "))}var o=/\+/g,r=e.cookie=function(o,l,s){if(l!==n){if(s=e.extend({},r.defaults,s),null===l&&(s.expires=-1),"number"==typeof s.expires){var d=s.expires,c=s.expires=new Date;c.setDate(c.getDate()+d)}return l=r.json?JSON.stringify(l):String(l),t.cookie=[encodeURIComponent(o),"=",r.raw?l:encodeURIComponent(l),s.expires?"; expires="+s.expires.toUTCString():"",s.path?"; path="+s.path:"",s.domain?"; domain="+s.domain:"",s.secure?"; secure":""].join("")}for(var p=r.raw?a:i,g=t.cookie.split("; "),u=0,f=g.length;u<f;u++){var h=g[u].split("=");if(p(h.shift())===o){var m=p(h.join("="));return r.json?JSON.parse(m):m}}return null};r.defaults={},e.removeCookie=function(t,n){return null!==e.cookie(t)&&(e.cookie(t,null,n),!0)}}(jQuery,document);var DataSaver={cookieName:"patternlab",addValue:function(e,t){var n=$.cookie(this.cookieName);n=null===n||""===n?e+"~"+t:n+"|"+e+"~"+t,$.cookie(this.cookieName,n)},updateValue:function(e,t){if(this.findValue(e)){for(var n="",a=$.cookie(this.cookieName).split("|"),i=0;i<a.length;i++){var o=a[i].split("~");o[0]==e&&(o[1]=t),n+=i>0?"|"+o[0]+"~"+o[1]:o[0]+"~"+o[1]}$.cookie(this.cookieName,n)}else this.addValue(e,t)},removeValue:function(e){for(var t="",n=$.cookie(this.cookieName).split("|"),a=0,i=0;i<n.length;i++){var o=n[i].split("~");o[0]!=e&&(t+=0===a?o[0]+"~"+o[1]:"|"+o[0]+"~"+o[1],a++)}$.cookie(this.cookieName,t)},findValue:function(e){if($.cookie(this.cookieName))for(var t=$.cookie(this.cookieName).split("|"),n=0;n<t.length;n++){var a=t[n].split("~");if(a[0]==e)return a[1]}return!1}};try{var template=document.getElementById("pl-pattern-nav-template"),templateCompiled=Hogan.compile(template.innerHTML),templateRendered=templateCompiled.render(navItems);document.getElementById("pl-pattern-nav-target").innerHTML=templateRendered;var template=document.getElementById("pl-ish-controls-template"),templateCompiled=Hogan.compile(template.innerHTML),templateRendered=templateCompiled.render(ishControls);document.getElementById("sg-controls").innerHTML=templateRendered}catch(e){var message="<h1>Nothing Here Yet</h1><p>Please generate your site before trying to view it.</p>";document.getElementById("pl-pattern-nav-target").innerHTML=message}var urlHandler={skipBack:!1,targetOrigin:"file:"==window.location.protocol?"*":window.location.protocol+"//"+window.location.host,getFileName:function(e,t){var n="patterns",a="";if(void 0===e)return a;if(void 0===t&&(t=!0),"all"==e)return"styleguide/html/styleguide.html";if("snapshots"==e)return"snapshots/index.html";var i=e.indexOf("viewall-")!=-1?viewAllPaths:patternPaths,o=e.replace("viewall-",""),r=this.getPatternInfo(o,i),l=r[0],s=r[1];if(void 0!==i[l]&&void 0!==i[l][s])a=i[l][s];else if(void 0!==i[l])for(var d in i[l])if(d.indexOf(s)!=-1){a=i[l][d];break}if(""===a)return a;var c=/\//g;if(e.indexOf("viewall-")!==-1&&0===e.indexOf("viewall-")&&""!==a)a=n+"/"+a.replace(c,"-")+"/index.html";else if(""!==a&&(a=n+"/"+a.replace(c,"-")+"/"+a.replace(c,"-"),t)){var p=void 0!==config.outputFileSuffixes&&void 0!==config.outputFileSuffixes.rendered?config.outputFileSuffixes.rendered:"";a=a+p+".html"}return a},getPatternInfo:function(e,t){for(var n=e.split("-"),a=1,i=n.length,o=n[0];void 0===t[o]&&a<i;)o+="-"+n[a],a++;var r=e.slice(o.length+1,e.length);return[o,r]},getRequestVars:function(){var e=new function(e){if(e.length>1)for(var t,n=0,a=e.substr(1).split("&");n<a.length;n++)t=a[n].split("="),this[unescape(t[0])]=t.length>1?unescape(t[1]):""}(window.location.search);return e},pushPattern:function(e,t){var n={pattern:e},a=urlHandler.getFileName(e),i=window.location.pathname;i="file"===window.location.protocol?i.replace("/public/index.html","public/"):i.replace(/\/index\.html/,"/");var o=window.location.protocol+"//"+window.location.host+i+a;if(t!=o){var r=JSON.stringify({event:"patternLab.updatePath",path:a});document.getElementById("sg-viewport").contentWindow.postMessage(r,urlHandler.targetOrigin)}else{var l="file:"==window.location.protocol?null:window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"?p="+e;void 0!==history.pushState&&history.pushState(n,null,l),document.getElementById("title").innerHTML="Pattern Lab - "+e,null!==document.getElementById("sg-raw")&&document.getElementById("sg-raw").setAttribute("href",urlHandler.getFileName(e))}},popPattern:function(e){var t,n=e.state;if(null===n)return void(this.skipBack=!1);null!==n&&(t=n.pattern);var a="";a=this.getFileName(t),""===a&&(a="styleguide/html/styleguide.html");var i=JSON.stringify({event:"patternLab.updatePath",path:a});document.getElementById("sg-viewport").contentWindow.postMessage(i,urlHandler.targetOrigin),document.getElementById("title").innerHTML="Pattern Lab - "+t,null!==document.getElementById("sg-raw")&&document.getElementById("sg-raw").setAttribute("href",urlHandler.getFileName(t))}};window.onpopstate=function(e){urlHandler.skipBack=!0,urlHandler.popPattern(e)};var modalViewer={active:!1,switchText:!0,template:"info",patternData:{},targetOrigin:"file:"===window.location.protocol?"*":window.location.protocol+"//"+window.location.host,onReady:function(){Dispatcher.addListener("insertPanels",modalViewer.insert),$(window).on("resize",function(){"false"===DataSaver.findValue("modalActive")&&modalViewer.slide($("#sg-modal-container").outerHeight())}),$("#sg-t-patterninfo").click(function(e){e.preventDefault(),$("#sg-tools-toggle").removeClass("active"),$(this).parents("ul").removeClass("active"),modalViewer.toggle()}),$("#sg-modal-close-btn").on("click",function(e){e.preventDefault(),obj=JSON.stringify({event:"patternLab.annotationsHighlightHide"}),document.getElementById("sg-viewport").contentWindow.postMessage(obj,modalViewer.targetOrigin),modalViewer.close()}),"true"===DataSaver.findValue("modalActive")&&(modalViewer.active=!0,$("#sg-t-patterninfo").html("Hide Pattern Info")),modalViewer.hide();var e=urlHandler.getRequestVars();void 0===e.view||"code"!==e.view&&"c"!==e.view||modalViewer.queryPattern(),void 0===e.view||"annotations"!==e.view&&"a"!==e.view||modalViewer.queryPattern()},toggle:function(){modalViewer.active===!1?modalViewer.queryPattern():(obj=JSON.stringify({event:"patternLab.annotationsHighlightHide"}),document.getElementById("sg-viewport").contentWindow.postMessage(obj,modalViewer.targetOrigin),modalViewer.close())},open:function(){modalViewer.close(),DataSaver.updateValue("modalActive","true"),modalViewer.active=!0,$("#sg-t-"+modalViewer.template+" .sg-checkbox").addClass("active"),$("#sg-modal-container").addClass("active"),modalViewer.show()},close:function(){var e;DataSaver.updateValue("modalActive","false"),modalViewer.active=!1,$("#sg-modal-container").removeClass("active"),$(".sg-checkbox").removeClass("active"),modalViewer.hide(),$("#sg-t-patterninfo").html("Show Pattern Info"),e=JSON.stringify({event:"patternLab.patternModalClose"}),document.getElementById("sg-viewport").contentWindow.postMessage(e,modalViewer.targetOrigin)},hide:function(){modalViewer.slide($("#sg-modal-container").outerHeight()+30)},insert:function(e,t,n,a){if(n){var i=JSON.stringify({event:"patternLab.patternModalInsert",patternPartial:t,modalContent:e.outerHTML});document.getElementById("sg-viewport").contentWindow.postMessage(i,modalViewer.targetOrigin)}else $("#sg-modal-content").html(e),modalViewer.open();a===!0&&$("#sg-t-patterninfo").html("Hide Pattern Info")},refresh:function(e,t,n){t&&modalViewer.hide(),panelsViewer.gatherPanels(e,t,n)},slide:function(e){e=0===e?0:-e,$("#sg-modal-container").css("bottom",e)},slideToAnnotation:function(e){for(els=document.querySelectorAll("#sg-annotations > .sg-annotations-list > li"),i=0;i<els.length;++i)els[i].classList.remove("active");for(i=0;i<els.length;++i)i+1==e&&(els[i].classList.add("active"),$(".sg-pattern-extra-info").animate({scrollTop:els[i].offsetTop-10},600))},show:function(){modalViewer.slide(0)},queryPattern:function(e){(void 0===e||e)&&(e=!0,DataSaver.updateValue("modalActive","true"),modalViewer.active=!0);var t=JSON.stringify({event:"patternLab.patternQuery",switchText:e});document.getElementById("sg-viewport").contentWindow.postMessage(t,modalViewer.targetOrigin)},receiveIframeMessage:function(e){if("file:"===window.location.protocol||e.origin===window.location.protocol+"//"+window.location.host){var t={};try{t="string"!=typeof e.data?e.data:JSON.parse(e.data)}catch(n){}void 0!==t.event&&"patternLab.pageLoad"==t.event?modalViewer.active===!1&&void 0!==t.patternpartial&&0===t.patternpartial.indexOf("viewall-")&&void 0!==config.defaultShowPatternInfo&&config.defaultShowPatternInfo?modalViewer.queryPattern(!1):modalViewer.active===!0&&modalViewer.queryPattern():void 0!==t.event&&"patternLab.patternQueryInfo"==t.event?modalViewer.refresh(t.patternData,t.iframePassback,t.switchText):void 0!==t.event&&"patternLab.annotationNumberClicked"==t.event&&modalViewer.slideToAnnotation(t.displayNumber)}}};$(document).ready(function(){modalViewer.onReady()}),window.addEventListener("message",modalViewer.receiveIframeMessage,!1);var panelsUtil={addClickEvents:function(e,t){for(var n=e.querySelectorAll("#sg-"+t+"-tabs li"),a=0;a<n.length;++a)n[a].onclick=function(e){e.preventDefault();var t=this.getAttribute("data-patternpartial"),n=this.getAttribute("data-panelid");panelsUtil.show(t,n)};return e},show:function(e,t){var n;for(n=document.querySelectorAll("#sg-"+e+"-tabs li"),i=0;i<n.length;++i)n[i].classList.remove("sg-tab-title-active");for(n=document.querySelectorAll("#sg-"+e+"-panels div.sg-tabs-panel"),i=0;i<n.length;++i)n[i].style.display="none";document.getElementById("sg-"+e+"-"+t+"-tab").classList.add("sg-tab-title-active"),document.getElementById("sg-"+e+"-"+t+"-panel").style.display="flex"}},PrismLanguages={languages:[],get:function(e){var t;for(i=0;i<this.languages.length;++i)if(t=this.languages[i],void 0!==t[e])return t[e];return"markup"},add:function(e){for(var t in e)if(e.hasOwnProperty(t))for(i=0;i<this.languages.length;++i)if(void 0!==this.languages[i][t])return void(this.languages[i][t]=e[t]);this.languages.push(e)}};PrismLanguages.add({twig:"markup"}),PrismLanguages.add({mustache:"markup"});var Panels={panels:[],count:function(){return this.panels.length},get:function(){return JSON.parse(JSON.stringify(this.panels))},add:function(e){for(i=0;i<this.panels.length;++i)if(e.id===this.panels[i].id)return;this.panels.push(e)}},fileSuffixPattern=void 0!==config.outputFileSuffixes&&void 0!==config.outputFileSuffixes.rawTemplate?config.outputFileSuffixes.rawTemplate:"",fileSuffixMarkup=void 0!==config.outputFileSuffixes&&void 0!==config.outputFileSuffixes.markupOnly?config.outputFileSuffixes.markupOnly:".markup-only";Panels.add({id:"sg-panel-pattern","default":!0,templateID:"pl-panel-template-code",httpRequest:!0,httpRequestReplace:fileSuffixPattern,httpRequestCompleted:!1,prismHighlight:!0,keyCombo:"ctrl+shift+u"}),Panels.add({id:"sg-panel-html",name:"HTML","default":!1,templateID:"pl-panel-template-code",httpRequest:!0,httpRequestReplace:fileSuffixMarkup+".html",httpRequestCompleted:!1,prismHighlight:!0,language:"markup",keyCombo:"ctrl+shift+y"}),Dispatcher.trigger("setupPanels");var panelsViewer={targetOrigin:"file:"===window.location.protocol?"*":window.location.protocol+"//"+window.location.host,initCopy:!1,initMoveTo:0,checkPanels:function(e,t,n,a){for(var i=0,o=0;o<e.length;++o)void 0!==e[o].content&&i++;i===Panels.count()&&panelsViewer.renderPanels(e,t,n,a)},gatherPanels:function(e,t,n){Dispatcher.addListener("checkPanels",panelsViewer.checkPanels);for(var a,i,o,r,l=Panels.get(),s=0;s<l.length;++s)if(r=l[s],void 0===r.name&&(r.name=e.patternEngineName||e.patternExtension,r.httpRequestReplace=r.httpRequestReplace+"."+e.patternExtension,r.language=e.patternExtension),void 0!==r.templateID&&r.templateID)if(void 0!==r.httpRequest&&r.httpRequest){var d=urlHandler.getFileName(e.patternPartial,!1),c=new XMLHttpRequest;c.onload=function(e,r,l,s){return function(){prismedContent=Prism.highlight(this.responseText,Prism.languages.html),a=document.getElementById(r[e].templateID),i=Hogan.compile(a.innerHTML),o=i.render({language:"html",code:prismedContent}),r[e].content=o,Dispatcher.trigger("checkPanels",[r,l,t,n])}}(s,l,e,t),c.open("GET",d+r.httpRequestReplace+"?"+(new Date).getTime(),!0),c.send()}else a=document.getElementById(r.templateID),i=Hogan.compile(a.innerHTML),o=i.render(e),l[s].content=o,Dispatcher.trigger("checkPanels",[l,e,t,n])},renderPanels:function(e,t,n,a){var i,o,r,l,s,d,c,p,g,u,f=t.patternPartial;for(t.panels=e,n||0!==t.patternDesc.length||(t.patternDesc="This pattern doesn't have a description."),t.patternNameCaps=t.patternName.toUpperCase(),g=document.createElement("div"),g.innerHTML=t.patternMarkup,s=1,t.annotations=[],delete t.patternMarkup,u=0;u<comments.comments.length;++u)p=comments.comments[u],c=g.querySelectorAll(p.el),c.length>0&&(l={displayNumber:s,el:p.el,title:p.title,comment:p.comment},t.annotations.push(l),s++);if(t.annotations.length>0){var h=JSON.stringify({event:"patternLab.annotationsHighlightShow",annotations:t.annotations});document.getElementById("sg-viewport").contentWindow.postMessage(h,panelsViewer.targetOrigin)}if(t.lineage.length>0)for(u=0;u<t.lineage.length;++u)u<t.lineage.length-1&&(t.lineage[u].hasComma=!0);if(t.lineageR.length>0)for(u=0;u<t.lineageR.length;++u)u<t.lineageR.length-1&&(t.lineageR[u].hasComma=!0);for(t.patternDescExists=t.patternDesc.length>0||void 0!==t.patternDescAdditions&&t.patternDescAdditions.length>0,t.lineageExists=0!==t.lineage.length,t.lineageRExists=0!==t.lineageR.length,t.patternStateExists=t.patternState.length>0,t.annotationExists=t.annotations.length>0,t.descBlockExists=t.patternDescExists||t.lineageExists||t.lineageRExists||t.patternStateExists||t.annotationExists,t.isPatternView=n===!1,i=document.getElementById("pl-panel-template-base"),o=Hogan.compile(i.innerHTML),r=o.render(t),d=document.createElement("div"),d.className="sg-modal-content-inner",d.innerHTML=r,r=d,r=panelsUtil.addClickEvents(r,f),u=0;u<e.length;++u)panel=e[u],panelTab="#sg-"+f+"-"+panel.id+"-tab",panelBlock="#sg-"+f+"-"+panel.id+"-panel",null!==r.querySelector(panelTab)&&panel["default"]&&(r.querySelector(panelTab).classList.add("sg-tab-title-active"),r.querySelector(panelBlock).style.display="block");$("#sg-code-lineage-fill a, #sg-code-lineager-fill a",r).on("click",function(e){e.preventDefault();var t=JSON.stringify({event:"patternLab.updatePath",path:urlHandler.getFileName($(this).attr("data-patternpartial"))});document.getElementById("sg-viewport").contentWindow.postMessage(t,panelsViewer.targetOrigin)}),Dispatcher.trigger("insertPanels",[r,f,n,a])}},patternFinder={data:[],active:!1,init:function(){for(var e in patternPaths)if(patternPaths.hasOwnProperty(e))for(var t in patternPaths[e]){var n={};n.patternPartial=e+"-"+t,n.patternPath=patternPaths[e][t],this.data.push(n)}var a=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.nonword(e.patternPartial)},queryTokenizer:Bloodhound.tokenizers.nonword,limit:10,local:this.data});a.initialize(),$("#sg-find .typeahead").typeahead({highlight:!0},{displayKey:"patternPartial",source:a.ttAdapter()}).on("typeahead:selected",patternFinder.onSelected).on("typeahead:autocompleted",patternFinder.onAutocompleted)},passPath:function(e){patternFinder.closeFinder();var t=JSON.stringify({event:"patternLab.updatePath",path:urlHandler.getFileName(e.patternPartial)});document.getElementById("sg-viewport").contentWindow.postMessage(t,urlHandler.targetOrigin)},onSelected:function(e,t){patternFinder.passPath(t)},onAutocompleted:function(e,t){patternFinder.passPath(t)},toggleFinder:function(){patternFinder.active?patternFinder.closeFinder():patternFinder.openFinder()},openFinder:function(){patternFinder.active=!0,$("#sg-find .typeahead").val(""),$("#sg-find").addClass("show-overflow")},closeFinder:function(){patternFinder.active=!1,document.activeElement.blur(),$("#sg-find").removeClass("show-overflow"),$("#sg-find .typeahead").val("")},receiveIframeMessage:function(e){if("file:"===window.location.protocol||e.origin===window.location.protocol+"//"+window.location.host){var t={};try{t="string"!=typeof e.data?e.data:JSON.parse(e.data)}catch(n){}return void 0!==t.event&&"patternLab.keyPress"==t.event&&"ctrl+shift+f"==t.keyPress?(patternFinder.toggleFinder(),!1):void 0}}};if(patternFinder.init(),window.addEventListener("message",patternFinder.receiveIframeMessage,!1),$("#sg-find .typeahead").focus(function(){patternFinder.active||patternFinder.openFinder()}),$("#sg-find .typeahead").blur(function(){patternFinder.closeFinder()}),self!=top){var path=window.location.toString(),parts=path.split("?"),options={event:"patternLab.pageLoad",path:parts[0]};patternData=document.getElementById("sg-pattern-data-footer").innerHTML,patternData=JSON.parse(patternData),options.patternpartial=void 0!==patternData.patternPartial?patternData.patternPartial:"all",""!==patternData.lineage&&(options.lineage=patternData.lineage);var targetOrigin="file:"==window.location.protocol?"*":window.location.protocol+"//"+window.location.host;parent.postMessage(options,targetOrigin);for(var aTags=document.getElementsByTagName("a"),i=0;i<aTags.length;i++)aTags[i].onclick=function(e){var t=this.getAttribute("href"),n=this.getAttribute("target");if(void 0===n||"_parent"!=n&&"_blank"!=n){if(!t||"#"===t)return e.preventDefault(),!1;e.preventDefault(),window.location.replace(t)}else;}}window.addEventListener("message",receiveIframeMessage,!1),function(e){function t(){var e=$(".sg-acc-panel.active").first(),t=(e.height(),w-E);e.height(t)}function n(){r(),s(),C=!1,c(u(y,void 0!==config.ishViewportRange?parseInt(config.ishViewportRange.s[1]):500))}function a(){r(),s(),C=!1,c(u(void 0!==config.ishViewportRange?parseInt(config.ishViewportRange.m[0]):500,void 0!==config.ishViewportRange?parseInt(config.ishViewportRange.m[1]):800))}function i(){r(),s(),C=!1,c(u(void 0!==config.ishViewportRange?parseInt(config.ishViewportRange.l[0]):800,void 0!==config.ishViewportRange?parseInt(config.ishViewportRange.l[1]):1200))}function o(){c(u(y,v))}function r(){L=!1,clearInterval(M),M=!1}function l(){L=!0,M=setInterval(o,800)}function s(){var e=V.width();H=!1,V.removeClass("hay-mode"),$("#sg-gen-container").removeClass("hay-mode"),c(Math.floor(e))}function d(){H=!0,$("#sg-gen-container").removeClass("vp-animate").width(y+b),V.removeClass("vp-animate").width(y);window.setTimeout(function(){$("#sg-gen-container").addClass("hay-mode").width(k+b),V.addClass("hay-mode").width(k),setInterval(function(){var e=V.width();g(e)},100)},200)}function c(e,t){var n;n=e>k?k:e<y?y:e,t===!1?$("#sg-gen-container,#sg-viewport").removeClass("vp-animate"):$("#sg-gen-container,#sg-viewport").addClass("vp-animate"),$("#sg-gen-container").width(n+b),V.width(n);var a="file:"===window.location.protocol?"*":window.location.protocol+"//"+window.location.host,i=JSON.stringify({event:"patternLab.resize",resize:"true"});document.getElementById("sg-viewport").contentWindow.postMessage(i,a),g(n),p(n)}function p(e){DataSaver.findValue("vpWidth")?DataSaver.updateValue("vpWidth",e):DataSaver.addValue("vpWidth",e)}function g(e,t,n){var a,i;"em"===t?(a=e,i=Math.floor(e*D)):(i=e,a=e/D),"updatePxInput"===n?I.val(i):"updateEmInput"===n?S.val(a.toFixed(2)):(S.val(a.toFixed(2)),I.val(i))}function u(e,t){return Math.floor(Math.random()*(t-e)+e)}function f(e){$("#sg-viewport").width(e),$("#sg-gen-container").width(1*e+14),g(e)}function h(){$(".sg-nav-container, .sg-nav-toggle, .sg-acc-handle, .sg-acc-panel").removeClass("active"),patternFinder.closeFinder()}function m(e){if("file:"===window.location.protocol||e.origin===window.location.protocol+"//"+window.location.host){var t={};try{t="string"!=typeof e.data?e.data:JSON.parse(e.data)}catch(o){}if(void 0!==t.event)if("patternLab.pageLoad"==t.event)urlHandler.skipBack||void 0!==history.state&&null!==history.state&&history.state.pattern===t.patternpartial||urlHandler.pushPattern(t.patternpartial,t.path),urlHandler.skipBack=!1;else if("patternLab.keyPress"==t.event){if("ctrl+shift+s"==t.keyPress)n();else if("ctrl+shift+m"==t.keyPress)a();else if("ctrl+shift+l"==t.keyPress)i();else if("ctrl+shift+d"==t.keyPress)L?r():l();else if("ctrl+shift+h"==t.keyPress)H?s():d();else if("ctrl+shift+0"==t.keyPress)c(320,!0);else if(found==t.keyPress.match(/ctrl\+shift\+([1-9])/)){var p=N[found[1]-1],g=p.indexOf("px")!==-1?"px":"em";p=p.replace(g,"");var u="px"===g?1*p:p*D;c(u,!0)}return!1}}}var v=document.body.clientWidth,w=$(document).height(),y=240,k=2600;if(void 0!==config.ishMinimum&&(y=parseInt(config.ishMinimum)),void 0!==config.ishMaximum&&(k=parseInt(config.ishMaximum)),void 0!==config.ishViewportRange&&(y=config.ishViewportRange.s[0],k=config.ishViewportRange.l[1]),config.ishViewportRange&&config.ishMaximum){var P=parseInt(config.ishViewportRange.l[1]),x=parseInt(config.ishMaximum);k=P>x?P:x}var b=14,V=$("#sg-viewport"),I=$(".sg-size-px"),S=$(".sg-size-em"),D=void 0!==config.ishFontSize?parseInt(config.ishFontSize):parseInt($("body").css("font-size")),E=$(".sg-header").height(),M=!1,L=!1,C=!0,H=!1;$(e).resize(function(){v=document.body.clientWidth,w=$(document).height(),t(),C===!0&&c(v,!1)}),$(".sg-acc-handle").on("click",function(e){e.preventDefault();var n=$(this),a=n.next(".sg-acc-panel"),i=n.parent().parent().hasClass("sg-acc-panel");i||($(".sg-acc-handle").not(n).removeClass("active"),$(".sg-acc-panel").not(a).removeClass("active")),n.toggleClass("active"),a.toggleClass("active"),t()}),$(".sg-nav-toggle").on("click",function(e){e.preventDefault(),$(".sg-nav-container").toggleClass("active")}),$("#sg-t-toggle").on("click",function(e){e.preventDefault(),$(this).parents("ul").toggleClass("active")}),$("#sg-size-toggle").on("click",function(e){e.preventDefault(),$(this).parents("ul").toggleClass("active")}),$(".sg-size[data-size]").on("click",function(e){e.preventDefault(),r(),s(),C=!1;var t=$(this).attr("data-size");t.indexOf("px")>-1&&(D=1),t=t.replace(/[^\d.-]/g,""),c(Math.floor(t*D))}),$("#sg-size-s").on("click",function(e){e.preventDefault(),n()}),jwerty.key("ctrl+shift+s",function(e){return n(),!1}),$("#sg-size-m").on("click",function(e){e.preventDefault(),a()}),jwerty.key("ctrl+shift+m",function(e){return i(),!1}),$("#sg-size-l").on("click",function(e){e.preventDefault(),i()}),jwerty.key("ctrl+shift+l",function(e){return i(),!1}),$("#sg-size-full").on("click",function(e){e.preventDefault(),r(),s(),C=!0,c(v)}),$("#sg-size-random").on("click",function(e){e.preventDefault(),r(),s(),C=!1,c(u(y,v))}),$("#sg-size-disco").on("click",function(e){e.preventDefault(),s(),C=!1,L?r():l()}),jwerty.key("ctrl+shift+d",function(e){return L?r():l(),!1}),$("#sg-size-hay").on("click",function(e){e.preventDefault(),r(),H?s():d()}),jwerty.key("ctrl+shift+h",function(e){H?s():d()}),I.on("keydown",function(e){var t=Math.floor($(this).val());38===e.keyCode?(t++,c(t,!1)):40===e.keyCode?(t--,c(t,!1)):13===e.keyCode&&(e.preventDefault(),c(t),$(this).blur())}),I.on("keyup",function(){var e=Math.floor($(this).val());g(e,"px","updateEmInput")}),S.on("keydown",function(e){var t=parseFloat($(this).val());38===e.keyCode?(t++,c(Math.floor(t*D),!1)):40===e.keyCode?(t--,c(Math.floor(t*D),!1)):13===e.keyCode&&(e.preventDefault(),c(Math.floor(t*D)))}),S.on("keyup",function(){var e=parseFloat($(this).val());g(e,"em","updatePxInput")}),jwerty.key("ctrl+shift+0",function(e){return e.preventDefault(),c(320,!0),!1});var N=[];$("#sg-mq a").each(function(e){N.push($(this).html()),$(this).on("click",function(e,t){return function(e){e.preventDefault();var n=$(t).html(),a=n.indexOf("px")!==-1?"px":"em";n=n.replace(a,"");var i="px"===a?1*n:n*D;c(i,!0)}}(e,this)),jwerty.key("ctrl+shift+"+(e+1),function(e){return function(t){var n=$(e).html(),a=n.indexOf("px")!==-1?"px":"em";n=n.replace(a,"");var i="px"===a?1*n:n*D;return c(i,!0),!1}}(this))}),$("#sg-gen-container").on("transitionend webkitTransitionEnd",function(e){var t="file:"===window.location.protocol?"*":window.location.protocol+"//"+window.location.host,n=JSON.stringify({event:"patternLab.resize",resize:"true"});document.getElementById("sg-viewport").contentWindow.postMessage(n,t)}),$("#sg-gen-container").on("touchstart",function(e){}),$("#sg-rightpull").mousedown(function(e){var t=e.clientX,n=V.width();return C=!1,$("#sg-cover").css("display","block"),$("#sg-cover").mousemove(function(e){var a;a=n+2*(e.clientX-t),a>y&&(DataSaver.findValue("vpWidth")?DataSaver.updateValue("vpWidth",a):DataSaver.addValue("vpWidth",a),c(a,!1))}),!1}),$("body").mouseup(function(){$("#sg-cover").unbind("mousemove"),$("#sg-cover").css("display","none")});var F=$("#sg-viewport").width();$("#sg-gen-container").width(F);var O=screen.width;void 0!==window.orientation&&(O=0===window.orientation?screen.width:screen.height),$(window).width()==O&&"ontouchstart"in document.documentElement&&$(window).width()<=1024?$("#sg-rightpull-container").width(0):$("#sg-viewport").width(F-14),g($("#sg-viewport").width());var B=urlHandler.getRequestVars(),R=0,T=!0;void 0!==B.h||void 0!==B.hay?d():void 0!==B.d||void 0!==B.disco?l():void 0!==B.w||void 0!==B.width?(R=void 0!==B.w?B.w:B.width,R=R.indexOf("em")!==-1?Math.floor(Math.floor(R.replace("em",""))*D):Math.floor(R.replace("px","")),DataSaver.updateValue("vpWidth",R),f(R)):T&&(R=DataSaver.findValue("vpWidth"))&&f(R);var q=window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html",""),z=void 0!==config.defaultPattern&&"string"==typeof config.defaultPattern&&config.defaultPattern.trim().length>0?config.defaultPattern:"all",A=q+"styleguide/html/styleguide.html?"+Date.now();if(void 0===B.p&&void 0===B.pattern||(z=void 0!==B.p?B.p:B.pattern),"all"!==z&&(patternPath=urlHandler.getFileName(z),A=""!==patternPath?q+patternPath+"?"+Date.now():A,document.getElementById("title").innerHTML="Pattern Lab - "+z,history.replaceState({pattern:z},null,null)),null!==document.getElementById("sg-raw")&&document.getElementById("sg-raw").setAttribute("href",urlHandler.getFileName(z)),urlHandler.skipBack=!0,document.getElementById("sg-viewport").contentWindow.location.replace(A),$("a[data-patternpartial]").on("click",function(e){e.preventDefault();var t=JSON.stringify({event:"patternLab.updatePath",path:urlHandler.getFileName($(this).attr("data-patternpartial"))});document.getElementById("sg-viewport").contentWindow.postMessage(t,urlHandler.targetOrigin),h()}),$("#sg-vp-wrap").click(function(){h()}),void 0!==window.orientation){var W=window.orientation;window.addEventListener("orientationchange",function(){window.orientation!=W&&($("#sg-gen-container").width($(window).width()),$("#sg-viewport").width($(window).width()),g($(window).width()),W=window.orientation)},!1)}window.addEventListener("message",m,!1)}(this);var pluginLoader={init:function(){for(var s,t,l,c,n,i=0;i<plugins.length;++i){var plugin=plugins[i];for(var key in plugin.templates)plugin.templates.hasOwnProperty(key)&&(t=document.getElementsByTagName("script"),l=t.length-1,s=t[l],n=document.createElement("script"),n.type="text/mustache",n.id=plugin.name.replace("/","-")+"-"+key+"-template",n.innerHTML=plugin.templates[key],s.parentNode.insertBefore(n,s.nextSibling));for(var k=0;k<plugin.stylesheets.length;++k)s=plugin.stylesheets[k],t=document.getElementsByTagName("link"),l=t.length-1,c=t[l],n=document.createElement("link"),n.type="text/css",n.rel="stylesheet",n.href="patternlab-components/"+plugin.name+"/"+s,n.media="screen",c.parentNode.insertBefore(n,c.nextSibling);$script(plugin.javascripts,plugin.name,eval("(function() { "+plugin.callback+" })")),$script.ready([plugin.name],eval("(function() { "+plugin.onready+" })"))}}};pluginLoader.init();