This file contains hidden or 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
public static MvcHtmlString DrawImage(this HtmlHelper helper, string imageUrl, string alt) | |
{ | |
if (CanBrowserHandleDataUris() & IsFileSizeCorrect(imageUrl)) | |
{ | |
// Get the file type | |
string fileType = Path.GetExtension(imageUrl); | |
if (fileType != null) | |
{ | |
fileType = fileType.Replace(".", ""); | |
} |
This file contains hidden or 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
/// <summary> | |
/// Converts the image to base64 string. | |
/// </summary> | |
/// <param name="imageUrl">The image URL.</param> | |
/// <returns></returns> | |
private static string ConvertImageToBase64String(string imageUrl) | |
{ | |
string imagepath = HttpContext.Current.Server.MapPath(imageUrl); | |
using (Image image = Image.FromFile(imagepath)) |
This file contains hidden or 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
/// <summary> | |
/// Determines if the browser is able to handle Data URIs based on its version. | |
/// </summary> | |
/// <returns> | |
/// <c>true</c> if this instance [can browser handle data uris]; otherwise, <c>false</c>. | |
/// </returns> | |
private static bool CanBrowserHandleDataUris() | |
{ | |
float browserVersion = -1; |
This file contains hidden or 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
public async Task<ActionResult> PageSpeed() | |
{ | |
// Hit the API | |
var client = new HttpClient(); | |
var homeResponseMessage = await client.GetAsync("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://www.deanhume.com&key={The_API_Key}"); | |
// Double check that it was successful | |
homeResponseMessage.EnsureSuccessStatusCode(); | |
var homeValue = await homeResponseMessage.Content.ReadAsStringAsync(); |
This file contains hidden or 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
public class PageSpeedEntity | |
{ | |
public string kind { get; set; } | |
public string id { get; set; } | |
public int responseCode { get; set; } | |
public string title { get; set; } | |
public int score { get; set; } | |
public PageStats pageStats { get; set; } | |
} |
This file contains hidden or 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
@{ | |
Layout = null; | |
} | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width" /> | |
<title>Bootstrap Typeahead</title> |
This file contains hidden or 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
$("#Search").typeahead({ | |
source: function (query, process) { | |
var countries = []; | |
map = {}; | |
// This is going to make an HTTP post request to the controller | |
return $.post('/Client/CountryLookup', { query: query }, function (data) { | |
// Loop through and push to the array | |
$.each(data, function (i, country) { |
This file contains hidden or 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
public class ClientController : Controller | |
{ | |
public ActionResult CountryLookup() | |
{ | |
var countries = new List<SearchTypeAheadEntity> | |
{ | |
new SearchTypeAheadEntity {ShortCode = "US", Name = "United States"}, | |
new SearchTypeAheadEntity {ShortCode = "CA", Name = "Canada"}, | |
new SearchTypeAheadEntity {ShortCode = "AF", Name = "Afghanistan"}, | |
new SearchTypeAheadEntity {ShortCode = "AL", Name = "Albania"}, |
This file contains hidden or 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
public static MvcHtmlString DrawImage(this HtmlHelper helper, string imageUrl, string alt) | |
{ | |
if (CanBrowserHandleWebPImages()) | |
{ | |
// Get the file type | |
string fileType = Path.GetExtension(imageUrl); | |
if (fileType != null) | |
{ | |
imageUrl = imageUrl.Replace(fileType, ".webp"); | |
} |
This file contains hidden or 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
<system.webServer> | |
<staticContent> | |
<mimeMap fileExtension=".webp" mimeType="image/webp" /> | |
</staticContent> | |
</system.webServer> |