Created
November 2, 2020 13:31
-
-
Save donalod/a81f3b7994a9ec0c3650ec975fe65a49 to your computer and use it in GitHub Desktop.
algolia_list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Webflow = Webflow || []; | |
Webflow.push(function () { | |
//var query = window.location.pathname.split("/").slice(-1).toString().replace(/-/g, " "); | |
var query = window.location.pathname.split("/").slice(-1).toString().replace(/-/g, " "); | |
if (query.split(" ").length == 3){ | |
query = query.split(" ")[0] | |
} | |
var options=""; | |
if (query.toLowerCase() == "slack") { | |
options="&restrictSearchableAttributes=vendor,product"; | |
} | |
var product_icon_src = $('#product-icon-src').attr("Src"); | |
$.ajax({ | |
type: "GET", | |
beforeSend: function(request) { | |
request.setRequestHeader("x-algolia-api-key", "xxxxxxxxxxxxxxxxxxxxxxxxx"); | |
request.setRequestHeader("x-algolia-application-id", "xxxxxxxxxxxxxxx"); | |
}, | |
url: "https://xxxxxxxxxxx.algolia.net/1/indexes/xxxxxxxxxxxxxx?query="+query+"&hitsPerPage=7&typoTolerance=min"+options, | |
dataType: "json", | |
success: function(msg) { | |
var results = msg.hits.sort(() => Math.random() - 0.5);; | |
if (results.length >= 2) { | |
$("#dynamic_agents").append('<ul id="unordered-dynamic-agents-list" class="integrations-agent-list"></ul>'); | |
results.forEach(function(hit){ | |
var agent_type = hit.agent_type | |
var agent_name = hit.name | |
var agent_class = hit.agent_type.replace(/\s+/g, '-').toLowerCase(); | |
switch (agent_class){ | |
case "http-request": | |
var agent_image = product_icon_src; | |
break; | |
default: | |
var agent_image = product_icon_src; | |
} | |
$("#unordered-dynamic-agents-list").append('<li class="integrations-agent-list-item"><img width="32" src="'+product_icon_src+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">'+hit.name+'</div></li>'); | |
//console.log(hit.name); | |
}) | |
} else { | |
// Just display the normal widgets | |
var webhook_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eaec31e6c54ed4b3a9b036b_agent-01.png"; | |
var imap_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eaec33aa0d3e450e3676bf2_agent-02.png"; | |
var email_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eaec35785c94f01dfafa1a0_agent-03.png"; | |
var http_request_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eac54a5c720320e0915d886_agent-04.png"; | |
var trigger_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eaec36ba0d3e4eb39676c2a_agent-05.png"; | |
var event_transform_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eaec37f85c94f89f8afa38c_agent-06.png"; | |
var send_to_story_agent_image = "https://uploads-ssl.webflow.com/5eaaf72f74a731a3d0744995/5eaec39300e6c624c4ef4d3d_agent-07.png"; | |
$("#dynamic_agents").append('<ul id="unordered-dynamic-agents-list" class="integrations-agent-list"></ul>'); | |
$("#unordered-dynamic-agents-list").append('<li class="integrations-agent-list-item"><img width="32" src="'+webhook_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">Webhook Agent</div></li><li class="integrations-agent-list-item"><img width="32" src="'+imap_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">IMAP Agent</div></li><li class="integrations-agent-list-item"><img width="32" src="'+email_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">Email Agent</div></li><li class="integrations-agent-list-item"><img width="32" src="'+http_request_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">HTTP Request Agent</div></li><li class="integrations-agent-list-item"><img src="'+trigger_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">Trigger Agent</div></li><li class="integrations-agent-list-item"><img width="32" src="'+event_transform_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">Event Transform Agent</div></li><li class="integrations-agent-list-item"><img width="32" src="'+send_to_story_agent_image+'" alt="" class="integrations-list-icon"><div class="integrations-agent-list-item-description">Send To Story Agent</div></li>'); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment