|
1 | 1 | (function(w){ |
| 2 | + |
2 | 3 | var sw = document.body.clientWidth, //Viewport Width |
3 | 4 | sh = document.body.clientHeight, //Viewport Height |
4 | 5 | minViewportWidth = 240, //Minimum Size for Viewport |
|
355 | 356 | } |
356 | 357 |
|
357 | 358 | // load the iframe source |
358 | | - var patternName = ""; |
| 359 | + var patternName = "all"; |
359 | 360 | var patternPath = ""; |
360 | 361 | var iFramePath = window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"styleguide/html/styleguide.html"; |
361 | 362 | if ((oGetVars.p != undefined) || (oGetVars.pattern != undefined)) { |
|
364 | 365 | iFramePath = (patternPath != "") ? window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+patternPath : iFramePath; |
365 | 366 | } |
366 | 367 |
|
367 | | - document.getElementById("sg-viewport").contentWindow.location.assign(iFramePath); |
| 368 | + if (patternName != "all") { |
| 369 | + document.getElementById("title").innerHTML = "Pattern Lab - "+patternName; |
| 370 | + history.replaceState({ "pattern": patternName }, null, null); |
| 371 | + } |
368 | 372 |
|
369 | | - history.replaceState({ "pattern": patternName }, null, null); |
| 373 | + urlHandler.skipBack = true; |
| 374 | + document.getElementById("sg-viewport").contentWindow.location.replace(iFramePath); |
370 | 375 |
|
371 | 376 | //IFrame functionality |
372 | 377 |
|
373 | 378 | //Scripts to run after the page has loaded into the iframe |
374 | 379 | $sgViewport.load(function (){ |
| 380 | + |
| 381 | + /* |
375 | 382 | var $sgSrc = $sgViewport.attr('src'), |
376 | 383 | $vp = $sgViewport.contents(), |
377 | 384 | $sgPattern = $vp.find('.sg-pattern'); |
|
431 | 438 | }); |
432 | 439 | $vp.find('.sg-annotations').show(); |
433 | 440 | } |
| 441 | + */ |
434 | 442 |
|
435 | 443 | // Pattern Click |
436 | 444 | // this doesn't work because patternlab-php assumes the iframe is being refreshed. not the overall app |
|
449 | 457 | // having it outside fixes an auto-close bug i ran into |
450 | 458 | $('.sg-nav a').not('.sg-acc-handle').on("click", function(e){ |
451 | 459 |
|
| 460 | + e.preventDefault(); |
| 461 | + |
452 | 462 | // update the iframe via the history api handler |
453 | | - urlHandler.pushPattern($(this).attr("data-patternpartial")); |
| 463 | + document.getElementById("sg-viewport").contentWindow.postMessage( { "path": urlHandler.getFileName($(this).attr("data-patternpartial")) }, urlHandler.targetOrigin); |
454 | 464 |
|
455 | 465 | // close up the menu |
456 | 466 | $(this).parents('.sg-acc-panel').toggleClass('active'); |
457 | 467 | $(this).parents('.sg-acc-panel').siblings('.sg-acc-handle').toggleClass('active'); |
458 | 468 |
|
459 | | - e.stopPropagation(); |
460 | | - |
461 | 469 | return false; |
462 | 470 |
|
463 | 471 | }); |
@@ -501,9 +509,12 @@ function receiveIframeMessage(event) { |
501 | 509 |
|
502 | 510 | if (!urlHandler.skipBack) { |
503 | 511 |
|
504 | | - var iFramePath = urlHandler.getFileName(event.data.patternpartial); |
505 | | - urlHandler.pushPattern(event.data.patternpartial, event.data.path); |
| 512 | + if ((history.state == null) || (history.state.pattern != event.data.patternpartial)) { |
| 513 | + urlHandler.pushPattern(event.data.patternpartial, event.data.path); |
| 514 | + } |
| 515 | + |
506 | 516 | if (wsnConnected) { |
| 517 | + var iFramePath = urlHandler.getFileName(event.data.patternpartial); |
507 | 518 | wsn.send( '{"url": "'+iFramePath+'", "patternpartial": "'+event.data.patternpartial+'" }' ); |
508 | 519 | } |
509 | 520 |
|
|
0 commit comments