Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit c9bcff5

Browse files
committed
updating pattern finder
1 parent 8f9bbde commit c9bcff5

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

public/styleguide/js/pattern-finder.js

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
var patternFinder = {
1010

11-
data: [],
11+
data: [],
12+
active: false,
1213

1314
init: function() {
1415

@@ -43,9 +44,7 @@ var patternFinder = {
4344

4445
passPath: function(item) {
4546
// update the iframe via the history api handler
46-
$('#sg-find').removeClass('show-overflow');
47-
$('#sg-find .typeahead').val("");
48-
$('.sg-acc-handle, .sg-acc-panel').removeClass('active');
47+
patternFinder.closeFinder();
4948
var obj = JSON.stringify({ "path": urlHandler.getFileName(item.patternPartial) });
5049
document.getElementById("sg-viewport").contentWindow.postMessage(obj, urlHandler.targetOrigin);
5150
},
@@ -58,22 +57,66 @@ var patternFinder = {
5857
patternFinder.passPath(item);
5958
},
6059

61-
toggleFinder: function() {},
60+
toggleFinder: function() {
61+
if (!patternFinder.active) {
62+
patternFinder.openFinder();
63+
} else {
64+
patternFinder.closeFinder();
65+
}
66+
},
6267

63-
openFinder: function() {},
68+
openFinder: function() {
69+
patternFinder.active = true;
70+
$('#sg-find .typeahead').val("");
71+
$("#sg-find").addClass('show-overflow');
72+
$('#sg-find .typeahead').focus();
73+
},
74+
75+
closeFinder: function() {
76+
patternFinder.active = false;
77+
$("#sg-find").removeClass('show-overflow');
78+
$('.sg-acc-handle, .sg-acc-panel').removeClass('active');
79+
$('#sg-find .typeahead').val("");
80+
},
81+
82+
receiveIframeMessage: function(event) {
83+
84+
var data = (typeof event.data !== "string") ? event.data : JSON.parse(event.data);
85+
86+
// does the origin sending the message match the current host? if not dev/null the request
87+
if ((window.location.protocol !== "file:") && (event.origin !== window.location.protocol+"//"+window.location.host)) {
88+
return;
89+
}
90+
91+
if (data.keyPress !== undefined) {
92+
if (data.keyPress == 'ctrl+shift+f') {
93+
patternFinder.toggleFinder();
94+
return false;
95+
}
96+
}
97+
98+
}
6499

65-
closeFinder: function() {}
66-
67100
}
68101

69102
patternFinder.init();
70103

71-
$('#sg-find').click(function(){ $(this).toggleClass('show-overflow') });
104+
window.addEventListener("message", patternFinder.receiveIframeMessage, false);
105+
106+
$('#sg-find .typeahead').focus(function() {
107+
if (!patternFinder.active) {
108+
patternFinder.openFinder();
109+
}
110+
});
111+
112+
$('#sg-find .typeahead').blur(function() {
113+
patternFinder.closeFinder();
114+
});
72115

73116
// jwerty stuff
74117
// toggle the annotations panel
75-
jwerty.key('cmd+shift+f/ctrl+shif+f', function (e) {
118+
jwerty.key('ctrl+shift+f', function (e) {
76119
$('.sg-find .sg-acc-handle, .sg-find .sg-acc-panel').addClass('active');
77-
$('#sg-find .typeahead').focus();
120+
patternFinder.toggleFinder();
78121
return false;
79122
});

public/styleguide/js/postmessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ if (self != top) {
3838
};
3939
}
4040

41-
// bind the keyboard shortcuts for various viewport resizings
42-
var keys = [ "s", "m", "l", "d", "h" ];
41+
// bind the keyboard shortcuts for various viewport resizings + pattern search
42+
var keys = [ "s", "m", "l", "d", "h", "f" ];
4343
for (var i = 0; i < keys.length; i++) {
4444
jwerty.key('ctrl+shift+'+keys[i], function (k,t) {
4545
return function(e) {

public/styleguide/js/styleguide.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@
505505
//Close all dropdowns and navigation
506506
function closePanels() {
507507
$('.sg-nav-container, .sg-nav-toggle, .sg-acc-handle, .sg-acc-panel').removeClass('active');
508+
patternFinder.closeFinder();
508509
}
509510

510511
// update the iframe with the source from clicked element in pull down menu. also close the menu

0 commit comments

Comments
 (0)