Skip to content

Commit

Permalink
Merge branch 'add-autocomplete-dropdown'
Browse files Browse the repository at this point in the history
  • Loading branch information
tbillington committed Dec 6, 2017
2 parents cf319f7 + 3a1632a commit 646d2b9
Show file tree
Hide file tree
Showing 21 changed files with 1,504 additions and 611 deletions.
403 changes: 258 additions & 145 deletions README.md

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{
"name": "website-search",
"version": "1.2.0",
"version": "1.3.0",
"private": true,
"devDependencies": {
"react-scripts": "1.0.10"
"fs-extra": "^4.0.2",
"inquirer": "^3.3.0",
"react-scripts": "1.0.14"
},
"dependencies": {
"pubsub-js": "^1.5.7",
"react": "15.6.1",
"react-dom": "15.6.1",
"sajari-react": "1.3.4",
"sajari-react": "1.5.0",
"stackqueue": "1.0.0"
},
"scripts": {
"start": "react-scripts start",
"start": "node prepare-start.js",
"build": "react-scripts build",
"dist": "react-scripts build && node dist.js",
"test": "react-scripts test --env=jsdom",
Expand Down
37 changes: 37 additions & 0 deletions prepare-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fs = require("fs-extra");
const spawn = require("child_process").spawnSync;
const inquirer = require("inquirer");

// copy a source file into index.html
const copyAndRun = source => {
try {
fs.copySync("public/" + source + ".html", "public/index.html");
} catch (e) {
console.log(e);
process.exit(1);
}
spawn("react-scripts", ["start"], { stdio: "inherit" });
process.exit(0);
};

const choices = ["inline", "searchbox", "overlay", "dynamic-content"];
const choice = process.argv[2];

// if the user has supplied an action run it without prompting
if (choices.indexOf(choice) !== -1) {
copyAndRun(choice);
}

// prompt the user for which action to run
inquirer
.prompt([
{
type: "list",
name: "choice",
message: "Which integration would you like to run?",
choices
}
])
.then(answers => {
copyAndRun(answers.choice);
});
86 changes: 86 additions & 0 deletions public/dynamic-content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Sajari: Dynamic Content Example UI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

<h2>Dynamic Content</h2>
<div id="dynamic-content"></div>


<!-- This script sets up the config for the search interface -->
<script>
var getUrlParam = function (e) { var t = new RegExp("[?&]" + e.replace(/[\[\]]/g, "\\$&") + "(=([^&#]*)|&|#|$)"), a = t.exec(window.location.href); return a && a[2] ? decodeURIComponent(a[2].replace(/\+/g, " ")) : "" };

var setup = function (u, r, n, t, a, s) { s = []; var e = function () { s.push(arguments) }, i = "ui"; return e.arr = s, u[t] = u[t] || [], u[t][i] = u[t][i] || [], u[t][i].push(e), e };

dynamicContent = setup(window, document, "script", "sajari");
dynamicContent({
mode: "dynamic-content",
project: "sajariptyltd", // Set this to your project.
collection: "sajari-com", // Set this to your collection.
values: { resultsPerPage: "3", "q": getUrlParam("q") },
attachDynamicContent: document.getElementById("dynamic-content"),
results: { showImages: false }, // Show images in results.
pipeline: "raw",
tracking: false,
searchOnLoad: true,
});
</script>

<style>
/**
* Page styling
*/

html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
background-color: #f7f7f7
}

body {
margin: 20px;
line-height: 24px
}

code,
pre {
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
background-color: #eee;
border: 1px solid #999;
padding: 2px;
border-radius: 4px;
font-size: 14px
}

pre {
padding: 10px
}

input,
button {
font-size: 16px;
}

div#search-box,
div#search-response,
div#content-block-response {
border: 2px dashed #ddd;
padding: 20px;
border-radius: 4px;
background-color: #fff;
margin: 10px;
}

ul li {
padding: 10px
}
</style>
</body>

</html>
137 changes: 0 additions & 137 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,137 +0,0 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Sajari: Website Search Example UI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

<h2>Overlay</h2>
<!-- This input box will launch the interface when the user presses enter -->
<input id="input-box" placeholder="Enter search query" onkeydown="inputKeyDown(event)">
<script>
function inputKeyDown(e) {
if (e.keyCode === 13 /* Enter key */) {
overlay("pub", "overlay-show");
overlay("pub", "values-set", { q: e.target.value });
overlay("pub", "search-send");
}
}
</script>
<br>

<!-- This input box will launch the interface when the user clicks it -->
<input onfocus="overlay('pub', 'overlay-show');" placeholder="Focus me to launch">
<!-- This button will launch the interface when the user clicks it -->
<button onclick="overlay('pub', 'overlay-show');">Launch Interface</button>

<h2>In Page</h2>
<div id="search-box"></div>
<div id="search-response"></div>

<h2>Content Block</h2>
<div id="content-block-response"></div>

<!-- This script sets up the config for the search interface -->
<script>
var getUrlParam = function (e) { var t = new RegExp("[?&]" + e.replace(/[\[\]]/g, "\\$&") + "(=([^&#]*)|&|#|$)"), a = t.exec(window.location.href); return a && a[2] ? decodeURIComponent(a[2].replace(/\+/g, " ")) : "" };

var setup = function (u, r, n, t, a, s) { s = []; var e = function () { s.push(arguments) }, i = "ui"; return e.arr = s, u[t] = u[t] || [], u[t][i] = u[t][i] || [], u[t][i].push(e), e };

inPage = setup(window, document, "script", "sajari", "//address.js");
inPage("config", {
project: "etstestest", // Set this to your project.
collection: "trent-kiwi", // Set this to your collection.
values: { resultsPerPage: "10", "q": getUrlParam("q") },
attachSearchBox: document.getElementById("search-box"),
attachSearchResponse: document.getElementById("search-response"),
pipeline: "website", // Run the website pipeline.
searchBoxPlaceHolder: "Type to search", // Placeholder text in search box.
results: { showImages: false }, // Show images in results.
tabFilters: { // Tabs configuration.
defaultTab: 'All', // Title of the default tab.
tabs: [{ title: 'All', filter: '' }, { title: 'Blog', filter: "dir1='blog'" }, { title: 'Other', filter: "dir1!='blog'" }], // Ordered list of tabs to show.
},
});

overlay = setup(window, document, "script", "sajari");
overlay("config", {
project: "etstestest", // Set this to your project.
collection: "trent-kiwi", // Set this to your collection.
values: { resultsPerPage: "10", "q": getUrlParam("q") },
overlay: true,
pipeline: "website", // Run the website pipeline.
searchBoxPlaceHolder: "Type to search", // Placeholder text in search box.
results: { showImages: false }, // Show images in results.
tabFilters: { // Tabs configuration.
defaultTab: 'All', // Title of the default tab.
tabs: [{ title: 'All', filter: '' }, { title: 'Blog', filter: "dir1='blog'" }, { title: 'Other', filter: "dir1!='blog'" }], // Ordered list of tabs to show.
},
});

contentBlock = setup(window, document, "script", "sajari");
contentBlock("config", {
project: "etstestest", // Set this to your project.
collection: "trent-kiwi", // Set this to your collection.
values: {},
attachContentBlock: document.getElementById("content-block-response"),
pipeline: "recent", // Run the website pipeline.
results: { showImages: false } // Show images in results.
});
contentBlock("pub", "search-send");
</script>

<style>
/**
* Page styling
*/

html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
background-color: #f7f7f7
}

body {
margin: 20px;
line-height: 24px
}

code,
pre {
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
background-color: #eee;
border: 1px solid #999;
padding: 2px;
border-radius: 4px;
font-size: 14px
}

pre {
padding: 10px
}

input,
button {
font-size: 16px;
}

div#search-box,
div#search-response,
div#content-block-response {
border: 2px dashed #ddd;
padding: 20px;
border-radius: 4px;
background-color: #fff;
margin: 10px;
}

ul li {
padding: 10px
}
</style>
</body>

</html>
93 changes: 93 additions & 0 deletions public/inline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Sajari: Inline Website Search Example UI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

<h2>Inline</h2>
<div id="search-box"></div>
<div id="search-response"></div>


<!-- This script sets up the config for the search interface -->
<script>
var getUrlParam = function (e) { var t = new RegExp("[?&]" + e.replace(/[\[\]]/g, "\\$&") + "(=([^&#]*)|&|#|$)"), a = t.exec(window.location.href); return a && a[2] ? decodeURIComponent(a[2].replace(/\+/g, " ")) : "" };

var setup = function (u, r, n, t, a, s) { s = []; var e = function () { s.push(arguments) }, i = "ui"; return e.arr = s, u[t] = u[t] || [], u[t][i] = u[t][i] || [], u[t][i].push(e), e };

inline = setup(window, document, "script", "sajari");
inline({
mode: "inline",
project: "sajariptyltd", // Set this to your project.
collection: "sajari-com", // Set this to your collection.
values: { resultsPerPage: "10", "q": getUrlParam("q") },
attachSearchBox: document.getElementById("search-box"),
attachSearchResponse: document.getElementById("search-response"),
results: { showImages: false }, // Show images in results.
pipeline: "website",
instantPipeline: "autocomplete",
inputPlaceholder: "Search",
maxSuggestions: 5,
tabFilters: { // Tabs configuration.
defaultTab: 'All', // Title of the default tab.
tabs: [{ title: 'All', filter: '' }, { title: 'Blog', filter: "dir1='blog'" }, { title: 'Other', filter: "dir1!='blog'" }], // Ordered list of tabs to show.
},
});
</script>

<style>
/**
* Page styling
*/

html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
background-color: #f7f7f7
}

body {
margin: 20px;
line-height: 24px
}

code,
pre {
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
background-color: #eee;
border: 1px solid #999;
padding: 2px;
border-radius: 4px;
font-size: 14px
}

pre {
padding: 10px
}

input,
button {
font-size: 16px;
}

div#search-box,
div#search-response,
div#content-block-response {
border: 2px dashed #ddd;
padding: 20px;
border-radius: 4px;
background-color: #fff;
margin: 10px;
}

ul li {
padding: 10px
}
</style>
</body>

</html>
Loading

0 comments on commit 646d2b9

Please sign in to comment.