Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 21 files changed
  • 0 comments
  • 1 contributor
9 LICENSE
... ... @@ -0,0 +1,9 @@
  1 +MIT License:
  2 +
  3 +Copyright (c) 2012 Justin Tucker
  4 +
  5 +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  6 +
  7 +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  8 +
  9 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 Modernizr-Server.sln
... ... @@ -0,0 +1,20 @@
  1 +
  2 +Microsoft Visual Studio Solution File, Format Version 11.00
  3 +# Visual Web Developer Express 2010
  4 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernizrServer", "Modernizr-Server\ModernizrServer.csproj", "{1BD18F12-92D6-4AAF-B799-0F82E61863E1}"
  5 +EndProject
  6 +Global
  7 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
  8 + Debug|Any CPU = Debug|Any CPU
  9 + Release|Any CPU = Release|Any CPU
  10 + EndGlobalSection
  11 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
  12 + {1BD18F12-92D6-4AAF-B799-0F82E61863E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  13 + {1BD18F12-92D6-4AAF-B799-0F82E61863E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
  14 + {1BD18F12-92D6-4AAF-B799-0F82E61863E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
  15 + {1BD18F12-92D6-4AAF-B799-0F82E61863E1}.Release|Any CPU.Build.0 = Release|Any CPU
  16 + EndGlobalSection
  17 + GlobalSection(SolutionProperties) = preSolution
  18 + HideSolutionNode = FALSE
  19 + EndGlobalSection
  20 +EndGlobal
26 Modernizr-Server/Default.aspx
... ... @@ -0,0 +1,26 @@
  1 +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ModernizrServer.Default" %>
  2 +
  3 +<!DOCTYPE html>
  4 +<html xmlns="http://www.w3.org/1999/xhtml">
  5 +<head runat="server">
  6 + <title>Modernizr Server</title>
  7 +</head>
  8 +<body>
  9 + <form id="form1" runat="server">
  10 + <div>
  11 + <h1>Modernizr Server</h1>
  12 + <p>Modernizr Server allows for an application to access browser capabilities detected
  13 + by Modernizr in server-side code.</p>
  14 +
  15 + <h2>Usage</h2>
  16 + <p>Include the ModernizrCookie.aspx page in your application, as well as the logic
  17 + found in the code-behind of this page. See the <a href="VideoTest.aspx">Video Test</a>
  18 + page for sample usage.</p>
  19 +
  20 + <h2>Modernizr Features</h2>
  21 + <p>See a <a href="ModernizrTestPage.aspx">full list of the features</a> detected by
  22 + Modernizr and which of those your browser supports!</p>
  23 + </div>
  24 + </form>
  25 +</body>
  26 +</html>
129 Modernizr-Server/Default.aspx.cs
... ... @@ -0,0 +1,129 @@
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Web;
  5 +using System.Web.UI;
  6 +using System.Web.UI.WebControls;
  7 +using System.Text;
  8 +using System.Dynamic;
  9 +
  10 +namespace ModernizrServer
  11 +{
  12 + public partial class Default : System.Web.UI.Page
  13 + {
  14 + //Configurable private members
  15 + private string _key = "Modernizr";
  16 + private int _MaxCookieAttempts = 3;
  17 +
  18 + /// <summary>
  19 + /// The magic behind Modernizr-Server
  20 + /// </summary>
  21 + /// <param name="sender"></param>
  22 + /// <param name="e"></param>
  23 + protected void Page_Load(object sender, EventArgs e)
  24 + {
  25 + if (Session[_key] != null && !String.IsNullOrEmpty(Session[_key].ToString()))
  26 + {
  27 + // The Modernizr object is in session and ready to use
  28 + dynamic Modernizr = Session[_key];
  29 +
  30 + if (Modernizr != null)
  31 + {
  32 + // At this point you are ready to test a particular property
  33 + // and do something with it
  34 +
  35 + }
  36 + else
  37 + {
  38 + // The Modernizr object cannot be retrieved from session.
  39 + //
  40 + // A workaround needs to be put here for this case.
  41 + // Ex: load a javascript file that checks the modernizr
  42 + // capability client-side and does something with it
  43 + }
  44 + }
  45 + else
  46 + {
  47 + // This is likely a new session...
  48 + //
  49 + // Check to see if a Modernizr cookie has been set
  50 + HttpCookieCollection TheCookies = Request.Cookies;
  51 + HttpCookie ModernizrCookie = TheCookies.Get(_key);
  52 + if (ModernizrCookie != null)
  53 + {
  54 + // Build the dynamic object from cookie found on user's machine
  55 + dynamic ModernizrDynamic = new ExpandoObject();
  56 + string[] FeatureArray = ModernizrCookie.Value.Split('|');
  57 + // Feature Array would look something like [ cssgradients:1, draganddrop:0, ....]
  58 + string[] FeatureKeyValueArray = new string[2];
  59 + foreach (string Feature in FeatureArray)
  60 + {
  61 + if (!String.IsNullOrWhiteSpace(Feature))
  62 + {
  63 + FeatureKeyValueArray = Feature.Split(new[] { ':' }, 2);
  64 + // FeatureKeyValueArray could be a simply property like [cssgradients,1]
  65 + // but it could be a more complicated property like [video,/ogg:1/webm:0/h264:1]
  66 + var f = ModernizrDynamic as IDictionary<String, object>;
  67 + if (FeatureKeyValueArray[1].StartsWith("/"))
  68 + {
  69 + dynamic ValueObject = new ExpandoObject();
  70 + string[] SubFeatureArray = FeatureKeyValueArray[1].Trim('/').Split('/');
  71 + //SubFeatureArray would be [ogg:1,webm:1,h264:1]
  72 + foreach (string SubFeature in SubFeatureArray)
  73 + {
  74 + string[] SubFeatureKeyValueArray = SubFeature.Split(new[] { ':' }, 2);
  75 + //SubFeatureKeyValueArray would be [ogg,1]
  76 + var v = ValueObject as IDictionary<String, object>;
  77 + //change the 0 or 1 to false or true so that boolean logic can be used
  78 + v[SubFeatureKeyValueArray[0]] = SubFeatureKeyValueArray[1] == "0" ? false : true;
  79 + }
  80 + f[FeatureKeyValueArray[0]] = ValueObject;
  81 + }
  82 + else
  83 + {
  84 + //change the 0 or 1 to false or true so that boolean logic can be used
  85 + f[FeatureKeyValueArray[0]] = FeatureKeyValueArray[1] == "0" ? false : true;
  86 + }
  87 + }
  88 + }
  89 + // Store the generated object in session for later use
  90 + Session[_key] = ModernizrDynamic;
  91 + }
  92 + else
  93 + {
  94 + // No Modernizr cookie exists, so we need to try to create one
  95 + if (Session["ModernizrCookieAttempts"] == null)
  96 + {
  97 + // ModernizrCookie has not been called before during this session
  98 + Session["ModernizrCookieAttempts"] = 1;
  99 + Response.Redirect("ModernizrCookie.aspx");
  100 + }
  101 + else
  102 + {
  103 + // ModernizrCookie has been called before during this session and was
  104 + // unsuccessful, or the user cleared their cookies during the session
  105 + // AND the session object was also lost. The latter would be unlikely,
  106 + // but I guess it's possible...
  107 + int CookieAttempts = int.Parse(Session["ModernizrCookieAttempts"].ToString());
  108 + if (CookieAttempts <= _MaxCookieAttempts)
  109 + {
  110 + CookieAttempts++;
  111 + Session["ModernizrCookieAttempts"] = CookieAttempts;
  112 + Response.Redirect("ModernizrCookie.aspx");
  113 + }
  114 + else
  115 + {
  116 + // The application has tried several times (depending on
  117 + // the configured "MaxCookieAttempts" variable) during this session
  118 + // to set a cookie and has been unsuccessful.
  119 + //
  120 + // A workaround needs to be put here for these cases.
  121 + // Ex: load a javascript file that checks the modernizr
  122 + // capability client-side and does something with it
  123 + }
  124 + }
  125 + }
  126 + }
  127 + }
  128 + }
  129 +}
48 Modernizr-Server/ModernizrCookie.aspx
... ... @@ -0,0 +1,48 @@
  1 +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModernizrCookie.aspx.cs" Inherits="ModernizrServer.ModernizrCookie" %>
  2 +
  3 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4 +
  5 +<html xmlns="http://www.w3.org/1999/xhtml">
  6 +<head runat="server">
  7 + <title></title>
  8 + <script src="js/modernizr.js" type="text/javascript"></script>
  9 +</head>
  10 +<body>
  11 + <form id="form1" runat="server"></form>
  12 + <script>
  13 + window.onload = function () {
  14 + var m = Modernizr,
  15 + f,
  16 + t,
  17 + c = '',
  18 + dt,
  19 + expires;
  20 + dt = new Date();
  21 + dt.setTime(dt.getTime() + (1 * 24 * 60 * 60 * 1000));
  22 + expires = "; expires=" + dt.toGMTString(); ;
  23 + for (f in m) {
  24 + if (f[0] == '_') {
  25 + continue
  26 + }
  27 + t = typeof m[f];
  28 + if (t == 'function') {
  29 + continue
  30 + }
  31 + c += (c ? '|' : 'Modernizr=') + f + ':';
  32 + if (t == 'object') {
  33 + for (var s in m[f]) {
  34 + c += '/' + s + ':' + (m[f][s] ? '1' : '0')
  35 + }
  36 + } else {
  37 + c += m[f] ? '1' : '0'
  38 + }
  39 + }
  40 + c += ';path=/';
  41 + try {
  42 + document.cookie = c + expires;
  43 + } catch (e) { }
  44 + window.top.location = 'default.aspx';
  45 + };
  46 + </script>
  47 +</body>
  48 +</html>
18 Modernizr-Server/ModernizrCookie.aspx.cs
... ... @@ -0,0 +1,18 @@
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Web;
  5 +using System.Web.UI;
  6 +using System.Web.UI.WebControls;
  7 +using System.Text;
  8 +using System.IO;
  9 +
  10 +namespace ModernizrServer
  11 +{
  12 + public partial class ModernizrCookie : System.Web.UI.Page
  13 + {
  14 + protected void Page_Load(object sender, EventArgs e)
  15 + {
  16 + }
  17 + }
  18 +}
122 Modernizr-Server/ModernizrServer.csproj
... ... @@ -0,0 +1,122 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3 + <PropertyGroup>
  4 + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  6 + <ProductVersion>
  7 + </ProductVersion>
  8 + <SchemaVersion>2.0</SchemaVersion>
  9 + <ProjectGuid>{1BD18F12-92D6-4AAF-B799-0F82E61863E1}</ProjectGuid>
  10 + <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
  11 + <OutputType>Library</OutputType>
  12 + <AppDesignerFolder>Properties</AppDesignerFolder>
  13 + <RootNamespace>ModernizrServer</RootNamespace>
  14 + <AssemblyName>Modernizr-Server</AssemblyName>
  15 + <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  16 + <UseIISExpress>false</UseIISExpress>
  17 + </PropertyGroup>
  18 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  19 + <DebugSymbols>true</DebugSymbols>
  20 + <DebugType>full</DebugType>
  21 + <Optimize>false</Optimize>
  22 + <OutputPath>bin\</OutputPath>
  23 + <DefineConstants>DEBUG;TRACE</DefineConstants>
  24 + <ErrorReport>prompt</ErrorReport>
  25 + <WarningLevel>4</WarningLevel>
  26 + </PropertyGroup>
  27 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  28 + <DebugType>pdbonly</DebugType>
  29 + <Optimize>true</Optimize>
  30 + <OutputPath>bin\</OutputPath>
  31 + <DefineConstants>TRACE</DefineConstants>
  32 + <ErrorReport>prompt</ErrorReport>
  33 + <WarningLevel>4</WarningLevel>
  34 + </PropertyGroup>
  35 + <ItemGroup>
  36 + <Reference Include="Microsoft.CSharp" />
  37 + <Reference Include="System" />
  38 + <Reference Include="System.Data" />
  39 + <Reference Include="System.Core" />
  40 + <Reference Include="System.Data.DataSetExtensions" />
  41 + <Reference Include="System.Web.Extensions" />
  42 + <Reference Include="System.Xml.Linq" />
  43 + <Reference Include="System.Drawing" />
  44 + <Reference Include="System.Web" />
  45 + <Reference Include="System.Xml" />
  46 + <Reference Include="System.Configuration" />
  47 + <Reference Include="System.Web.Services" />
  48 + <Reference Include="System.EnterpriseServices" />
  49 + <Reference Include="System.Web.DynamicData" />
  50 + <Reference Include="System.Web.Entity" />
  51 + <Reference Include="System.Web.ApplicationServices" />
  52 + </ItemGroup>
  53 + <ItemGroup>
  54 + <Content Include="Default.aspx" />
  55 + <Content Include="js\modernizr.js" />
  56 + <Content Include="ModernizrCookie.aspx" />
  57 + <Content Include="ModernizrTestPage.aspx" />
  58 + <Content Include="VideoTest.aspx" />
  59 + <Content Include="Web.config" />
  60 + <Content Include="Web.Debug.config">
  61 + <DependentUpon>Web.config</DependentUpon>
  62 + </Content>
  63 + <Content Include="Web.Release.config">
  64 + <DependentUpon>Web.config</DependentUpon>
  65 + </Content>
  66 + </ItemGroup>
  67 + <ItemGroup>
  68 + <Compile Include="VideoTest.aspx.cs">
  69 + <DependentUpon>VideoTest.aspx</DependentUpon>
  70 + <SubType>ASPXCodeBehind</SubType>
  71 + </Compile>
  72 + <Compile Include="VideoTest.aspx.designer.cs">
  73 + <DependentUpon>VideoTest.aspx</DependentUpon>
  74 + </Compile>
  75 + <Content Include="Default.aspx.cs">
  76 + <DependentUpon>Default.aspx</DependentUpon>
  77 + <SubType>ASPXCodeBehind</SubType>
  78 + </Content>
  79 + <Content Include="ModernizrCookie.aspx.cs">
  80 + <DependentUpon>ModernizrCookie.aspx</DependentUpon>
  81 + <SubType>ASPXCodeBehind</SubType>
  82 + </Content>
  83 + <Content Include="ModernizrTestPage.aspx.cs">
  84 + <DependentUpon>ModernizrTestPage.aspx</DependentUpon>
  85 + <SubType>ASPXCodeBehind</SubType>
  86 + </Content>
  87 + <Compile Include="Properties\AssemblyInfo.cs" />
  88 + </ItemGroup>
  89 + <ItemGroup>
  90 + <None Include="assets\video\h.264\gizmo.mp4" />
  91 + <None Include="assets\video\ogg\gizmo.ogv" />
  92 + <None Include="assets\video\webm\gizmo.webm" />
  93 + </ItemGroup>
  94 + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  95 + <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
  96 + <ProjectExtensions>
  97 + <VisualStudio>
  98 + <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
  99 + <WebProjectProperties>
  100 + <UseIIS>False</UseIIS>
  101 + <AutoAssignPort>True</AutoAssignPort>
  102 + <DevelopmentServerPort>4657</DevelopmentServerPort>
  103 + <DevelopmentServerVPath>/</DevelopmentServerVPath>
  104 + <IISUrl>
  105 + </IISUrl>
  106 + <NTLMAuthentication>False</NTLMAuthentication>
  107 + <UseCustomServer>False</UseCustomServer>
  108 + <CustomServerUrl>
  109 + </CustomServerUrl>
  110 + <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
  111 + </WebProjectProperties>
  112 + </FlavorProperties>
  113 + </VisualStudio>
  114 + </ProjectExtensions>
  115 + <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  116 + Other similar extension points exist, see Microsoft.Common.targets.
  117 + <Target Name="BeforeBuild">
  118 + </Target>
  119 + <Target Name="AfterBuild">
  120 + </Target>
  121 + -->
  122 +</Project>
15 Modernizr-Server/ModernizrTestPage.aspx
... ... @@ -0,0 +1,15 @@
  1 +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModernizrTestPage.aspx.cs" Inherits="ModernizrServer.ModernizrTestPage" %>
  2 +
  3 +<!DOCTYPE html>
  4 +
  5 +<html xmlns="http://www.w3.org/1999/xhtml">
  6 +<head runat="server">
  7 + <title>Modernizr Server - All Features Detected</title>
  8 +</head>
  9 +<body>
  10 + <form id="form1" runat="server">
  11 + <div id="ModernizrResults" runat="server">
  12 + </div>
  13 + </form>
  14 +</body>
  15 +</html>
46 Modernizr-Server/ModernizrTestPage.aspx.cs
... ... @@ -0,0 +1,46 @@
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Web;
  5 +using System.Web.UI;
  6 +using System.Web.UI.WebControls;
  7 +using System.Text;
  8 +
  9 +namespace ModernizrServer
  10 +{
  11 + public partial class ModernizrTestPage : System.Web.UI.Page
  12 + {
  13 + protected void Page_Load(object sender, EventArgs e)
  14 + {
  15 + dynamic ModernizrDynamic = Session["Modernizr"];
  16 +
  17 + // For testing purposes only - print out all of the key/value objects
  18 + // within the Modernizr object
  19 + IDictionary<string, object> ModernizrDict = (IDictionary<string, object>)ModernizrDynamic;
  20 + IDictionary<string, object> ModernizrSubDict;
  21 + StringBuilder sb = new StringBuilder();
  22 + sb.Append("<p>Modernizr values found:</p><ul>");
  23 + foreach (var kvp in ModernizrDict)
  24 + {
  25 + sb.AppendFormat("<li>{0}:", kvp.Key);
  26 + if (kvp.Value.GetType() == typeof(bool))
  27 + {
  28 + sb.Append(kvp.Value.ToString());
  29 + }
  30 + else
  31 + {
  32 + sb.Append("<ul>");
  33 + ModernizrSubDict = (IDictionary<string, object>)kvp.Value;
  34 + foreach (var subkvp in ModernizrSubDict)
  35 + {
  36 + sb.AppendFormat("<li>{0}:{1}</li>", subkvp.Key, subkvp.Value.ToString());
  37 + }
  38 + sb.Append("</ul>");
  39 + }
  40 + sb.Append("</li>");
  41 + }
  42 + sb.Append("</ul>");
  43 + ModernizrResults.InnerHtml = sb.ToString();
  44 + }
  45 + }
  46 +}
35 Modernizr-Server/Properties/AssemblyInfo.cs
... ... @@ -0,0 +1,35 @@
  1 +using System.Reflection;
  2 +using System.Runtime.CompilerServices;
  3 +using System.Runtime.InteropServices;
  4 +
  5 +// General Information about an assembly is controlled through the following
  6 +// set of attributes. Change these attribute values to modify the information
  7 +// associated with an assembly.
  8 +[assembly: AssemblyTitle("Modernizr_Server")]
  9 +[assembly: AssemblyDescription("")]
  10 +[assembly: AssemblyConfiguration("")]
  11 +[assembly: AssemblyCompany("")]
  12 +[assembly: AssemblyProduct("Modernizr_Server")]
  13 +[assembly: AssemblyCopyright("")]
  14 +[assembly: AssemblyTrademark("")]
  15 +[assembly: AssemblyCulture("")]
  16 +
  17 +// Setting ComVisible to false makes the types in this assembly not visible
  18 +// to COM components. If you need to access a type in this assembly from
  19 +// COM, set the ComVisible attribute to true on that type.
  20 +[assembly: ComVisible(false)]
  21 +
  22 +// The following GUID is for the ID of the typelib if this project is exposed to COM
  23 +[assembly: Guid("87d8ab86-def2-4600-8ba8-205c4ad2af30")]
  24 +
  25 +// Version information for an assembly consists of the following four values:
  26 +//
  27 +// Major Version
  28 +// Minor Version
  29 +// Build Number
  30 +// Revision
  31 +//
  32 +// You can specify all the values or you can default the Revision and Build Numbers
  33 +// by using the '*' as shown below:
  34 +[assembly: AssemblyVersion("1.0.0.0")]
  35 +[assembly: AssemblyFileVersion("1.0.0.0")]
22 Modernizr-Server/VideoTest.aspx
... ... @@ -0,0 +1,22 @@
  1 +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VideoTest.aspx.cs" Inherits="ModernizrServer.VideoTest" %>
  2 +
  3 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4 +
  5 +<html xmlns="http://www.w3.org/1999/xhtml">
  6 +<head runat="server">
  7 + <title>Modernizr Server - Video Test</title>
  8 +</head>
  9 +<body>
  10 + <form id="form1" runat="server">
  11 + <div>
  12 + <h1>Modernizr Video Test</h1>
  13 + <p>A sample video page that demonstrates how Modernizr Server would test
  14 + for video support and include the appropriate source(s). Video samples are from
  15 + <a href="http://www.808.dk/?code-html-5-video">808.dk</a> and are for demonstration
  16 + purposes only.</p>
  17 + <p><strong><asp:Literal ID="VideoCapabilities" runat="server"></asp:Literal></strong></p>
  18 + <asp:PlaceHolder ID="VideoPlaceHolder" runat="server"></asp:PlaceHolder>
  19 + </div>
  20 + </form>
  21 +</body>
  22 +</html>
69 Modernizr-Server/VideoTest.aspx.cs
... ... @@ -0,0 +1,69 @@
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Web;
  5 +using System.Web.UI;
  6 +using System.Web.UI.WebControls;
  7 +using System.Web.UI.HtmlControls;
  8 +
  9 +namespace ModernizrServer
  10 +{
  11 + public partial class VideoTest : System.Web.UI.Page
  12 + {
  13 + protected void Page_Load(object sender, EventArgs e)
  14 + {
  15 + dynamic Modernizr = Session["Modernizr"];
  16 +
  17 + if (Modernizr != null)
  18 + {
  19 + if (Modernizr.video != null)
  20 + {
  21 + HtmlGenericControl VideoControl = new HtmlGenericControl("video");
  22 + VideoControl.Attributes.Add("autoplay", "autoplay");
  23 + VideoControl.Attributes.Add("controls", "controls");
  24 + if (Modernizr.video.h264)
  25 + {
  26 + VideoCapabilities.Text += "Your browser supports h.264. ";
  27 + HtmlGenericControl VideoSource = new HtmlGenericControl("source");
  28 + VideoSource.Attributes.Add("src", "assets/video/h.264/gizmo.mp4");
  29 + VideoControl.Controls.Add(VideoSource);
  30 + }
  31 + if (Modernizr.video.webm)
  32 + {
  33 + VideoCapabilities.Text += "Your browser supports webm. ";
  34 + HtmlGenericControl VideoSource = new HtmlGenericControl("source");
  35 + VideoSource.Attributes.Add("src", "assets/video/webm/gizmo.webm");
  36 + VideoSource.Attributes.Add("type", "video/webm");
  37 + VideoControl.Controls.Add(VideoSource);
  38 + }
  39 + if (Modernizr.video.ogg)
  40 + {
  41 + VideoCapabilities.Text += "Your browser supports ogg. ";
  42 + HtmlGenericControl VideoSource = new HtmlGenericControl("source");
  43 + VideoSource.Attributes.Add("src", "assets/video/ogg/gizmo.ogv");
  44 + VideoSource.Attributes.Add("type", "video/ogg");
  45 + VideoControl.Controls.Add(VideoSource);
  46 + }
  47 + else
  48 + {
  49 + VideoCapabilities.Text = "Your browser does not support h.264, webm or ogg video formats";
  50 + }
  51 + VideoPlaceHolder.Controls.Add(VideoControl);
  52 + }
  53 + else
  54 + {
  55 + VideoCapabilities.Text = "Your browser does not support h.264, webm or ogg video formats";
  56 + }
  57 + // End Example
  58 + }
  59 + else
  60 + {
  61 + // The Modernizr object cannot be retrieved from session.
  62 + //
  63 + // A workaround needs to be put here for this case.
  64 + // Ex: load a javascript file that checks the modernizr
  65 + // capability client-side and does something with it
  66 + }
  67 + }
  68 + }
  69 +}
42 Modernizr-Server/VideoTest.aspx.designer.cs
... ... @@ -0,0 +1,42 @@
  1 +//------------------------------------------------------------------------------
  2 +// <auto-generated>
  3 +// This code was generated by a tool.
  4 +//
  5 +// Changes to this file may cause incorrect behavior and will be lost if
  6 +// the code is regenerated.
  7 +// </auto-generated>
  8 +//------------------------------------------------------------------------------
  9 +
  10 +namespace ModernizrServer {
  11 +
  12 +
  13 + public partial class VideoTest {
  14 +
  15 + /// <summary>
  16 + /// form1 control.
  17 + /// </summary>
  18 + /// <remarks>
  19 + /// Auto-generated field.
  20 + /// To modify move field declaration from designer file to code-behind file.
  21 + /// </remarks>
  22 + protected global::System.Web.UI.HtmlControls.HtmlForm form1;
  23 +
  24 + /// <summary>
  25 + /// VideoCapabilities control.
  26 + /// </summary>
  27 + /// <remarks>
  28 + /// Auto-generated field.
  29 + /// To modify move field declaration from designer file to code-behind file.
  30 + /// </remarks>
  31 + protected global::System.Web.UI.WebControls.Literal VideoCapabilities;
  32 +
  33 + /// <summary>
  34 + /// VideoPlaceHolder control.
  35 + /// </summary>
  36 + /// <remarks>
  37 + /// Auto-generated field.
  38 + /// To modify move field declaration from designer file to code-behind file.
  39 + /// </remarks>
  40 + protected global::System.Web.UI.WebControls.PlaceHolder VideoPlaceHolder;
  41 + }
  42 +}
30 Modernizr-Server/Web.Debug.config
... ... @@ -0,0 +1,30 @@
  1 +<?xml version="1.0"?>
  2 +
  3 +<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
  4 +
  5 +<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  6 + <!--
  7 + In the example below, the "SetAttributes" transform will change the value of
  8 + "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
  9 + finds an atrribute "name" that has a value of "MyDB".
  10 +
  11 + <connectionStrings>
  12 + <add name="MyDB"
  13 + connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
  14 + xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  15 + </connectionStrings>
  16 + -->
  17 + <system.web>
  18 + <!--
  19 + In the example below, the "Replace" transform will replace the entire
  20 + <customErrors> section of your web.config file.
  21 + Note that because there is only one customErrors section under the
  22 + <system.web> node, there is no need to use the "xdt:Locator" attribute.
  23 +
  24 + <customErrors defaultRedirect="GenericError.htm"
  25 + mode="RemoteOnly" xdt:Transform="Replace">
  26 + <error statusCode="500" redirect="InternalError.htm"/>
  27 + </customErrors>
  28 + -->
  29 + </system.web>
  30 +</configuration>
31 Modernizr-Server/Web.Release.config
... ... @@ -0,0 +1,31 @@
  1 +<?xml version="1.0"?>
  2 +
  3 +<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
  4 +
  5 +<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  6 + <!--
  7 + In the example below, the "SetAttributes" transform will change the value of
  8 + "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
  9 + finds an atrribute "name" that has a value of "MyDB".
  10 +
  11 + <connectionStrings>
  12 + <add name="MyDB"
  13 + connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
  14 + xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  15 + </connectionStrings>
  16 + -->
  17 + <system.web>
  18 + <compilation xdt:Transform="RemoveAttributes(debug)" />
  19 + <!--
  20 + In the example below, the "Replace" transform will replace the entire
  21 + <customErrors> section of your web.config file.
  22 + Note that because there is only one customErrors section under the
  23 + <system.web> node, there is no need to use the "xdt:Locator" attribute.
  24 +
  25 + <customErrors defaultRedirect="GenericError.htm"
  26 + mode="RemoteOnly" xdt:Transform="Replace">
  27 + <error statusCode="500" redirect="InternalError.htm"/>
  28 + </customErrors>
  29 + -->
  30 + </system.web>
  31 +</configuration>
20 Modernizr-Server/Web.config
... ... @@ -0,0 +1,20 @@
  1 +<?xml version="1.0"?>
  2 +
  3 +<!--
  4 + For more information on how to configure your ASP.NET application, please visit
  5 + http://go.microsoft.com/fwlink/?LinkId=169433
  6 + -->
  7 +
  8 +<configuration>
  9 + <connectionStrings />
  10 + <system.web>
  11 + <compilation debug="false" targetFramework="4.0" />
  12 + <authentication mode="Windows">
  13 + </authentication>
  14 + <sessionState mode="InProc" cookieless="false" timeout="30" />
  15 + </system.web>
  16 +
  17 + <system.webServer>
  18 + <modules runAllManagedModulesForAllRequests="true"/>
  19 + </system.webServer>
  20 +</configuration>
BIN  Modernizr-Server/assets/video/h.264/gizmo.mp4
Binary file not shown
BIN  Modernizr-Server/assets/video/ogg/gizmo.ogv
Binary file not shown
BIN  Modernizr-Server/assets/video/webm/gizmo.webm
Binary file not shown
1  Modernizr-Server/js/modernizr.js
... ... @@ -0,0 +1 @@
  1 +window.Modernizr = (function (window, document, undefined) { var version = '2.5.3', Modernizr = {}, enableClasses = true, docElement = document.documentElement, mod = 'modernizr', modElem = document.createElement(mod), mStyle = modElem.style, inputElem = document.createElement('input'), smile = ':)', toString = {}.toString, prefixes = ' -webkit- -moz- -o- -ms- '.split(' '), omPrefixes = 'Webkit Moz O ms', cssomPrefixes = omPrefixes.split(' '), domPrefixes = omPrefixes.toLowerCase().split(' '), ns = { 'svg': 'http://www.w3.org/2000/svg' }, tests = {}, inputs = {}, attrs = {}, classes = [], slice = classes.slice, featureName, injectElementWithStyles = function (rule, callback, nodes, testnames) { var style, ret, node, div = document.createElement('div'), body = document.body, fakeBody = body ? body : document.createElement('body'); if (parseInt(nodes, 10)) { while (nodes--) { node = document.createElement('div'); node.id = testnames ? testnames[nodes] : mod + (nodes + 1); div.appendChild(node) } } style = ['&#173;', '<style>', rule, '</style>'].join(''); div.id = mod; fakeBody.innerHTML += style; fakeBody.appendChild(div); if (!body) { fakeBody.style.background = ""; docElement.appendChild(fakeBody) } ret = callback(div, rule); !body ? fakeBody.parentNode.removeChild(fakeBody) : div.parentNode.removeChild(div); return !!ret }, testMediaQuery = function (mq) { var matchMedia = window.matchMedia || window.msMatchMedia; if (matchMedia) { return matchMedia(mq).matches } var bool; injectElementWithStyles('@media ' + mq + ' { #' + mod + ' { position: absolute; } }', function (node) { bool = (window.getComputedStyle ? getComputedStyle(node, null) : node.currentStyle)['position'] == 'absolute' }); return bool }, isEventSupported = (function () { var TAGNAMES = { 'select': 'input', 'change': 'input', 'submit': 'form', 'reset': 'form', 'error': 'img', 'load': 'img', 'abort': 'img' }; function isEventSupported(eventName, element) { element = element || document.createElement(TAGNAMES[eventName] || 'div'); eventName = 'on' + eventName; var isSupported = eventName in element; if (!isSupported) { if (!element.setAttribute) { element = document.createElement('div') } if (element.setAttribute && element.removeAttribute) { element.setAttribute(eventName, ''); isSupported = is(element[eventName], 'function'); if (!is(element[eventName], 'undefined')) { element[eventName] = undefined } element.removeAttribute(eventName) } } element = null; return isSupported } return isEventSupported })(); var _hasOwnProperty = ({}).hasOwnProperty, hasOwnProperty; if (!is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined')) { hasOwnProperty = function (object, property) { return _hasOwnProperty.call(object, property) } } else { hasOwnProperty = function (object, property) { return ((property in object) && is(object.constructor.prototype[property], 'undefined')) } } if (!Function.prototype.bind) { Function.prototype.bind = function bind(that) { var target = this; if (typeof target != "function") { throw new TypeError(); } var args = slice.call(arguments, 1), bound = function () { if (this instanceof bound) { var F = function () { }; F.prototype = target.prototype; var self = new F; var result = target.apply(self, args.concat(slice.call(arguments))); if (Object(result) === result) { return result } return self } else { return target.apply(that, args.concat(slice.call(arguments))) } }; return bound } } function setCss(str) { mStyle.cssText = str } function setCssAll(str1, str2) { return setCss(prefixes.join(str1 + ';') + (str2 || '')) } function is(obj, type) { return typeof obj === type } function contains(str, substr) { return !! ~('' + str).indexOf(substr) } function testProps(props, prefixed) { for (var i in props) { if (mStyle[props[i]] !== undefined) { return prefixed == 'pfx' ? props[i] : true } } return false } function testDOMProps(props, obj, elem) { for (var i in props) { var item = obj[props[i]]; if (item !== undefined) { if (elem === false) return props[i]; if (is(item, 'function')) { return item.bind(elem || obj) } return item } } return false } function testPropsAll(prop, prefixed, elem) { var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1), props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' '); if (is(prefixed, "string") || is(prefixed, "undefined")) { return testProps(props, prefixed) } else { props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' '); return testDOMProps(props, prefixed, elem) } } var testBundle = (function (styles, tests) { var style = styles.join(''), len = tests.length; injectElementWithStyles(style, function (node, rule) { var style = document.styleSheets[document.styleSheets.length - 1], cssText = style ? (style.cssRules && style.cssRules[0] ? style.cssRules[0].cssText : style.cssText || '') : '', children = node.childNodes, hash = {}; while (len--) { hash[children[len].id] = children[len] } Modernizr['touch'] = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch || (hash['touch'] && hash['touch'].offsetTop) === 9; Modernizr['csstransforms3d'] = (hash['csstransforms3d'] && hash['csstransforms3d'].offsetLeft) === 9 && hash['csstransforms3d'].offsetHeight === 3; Modernizr['generatedcontent'] = (hash['generatedcontent'] && hash['generatedcontent'].offsetHeight) >= 1; Modernizr['fontface'] = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0 }, len, tests) })(['@font-face {font-family:"font";src:url("https://")}', ['@media (', prefixes.join('touch-enabled),('), mod, ')', '{#touch{top:9px;position:absolute}}'].join(''), ['@media (', prefixes.join('transform-3d),('), mod, ')', '{#csstransforms3d{left:9px;position:absolute;height:3px;}}'].join(''), ['#generatedcontent:after{content:"', smile, '";visibility:hidden}'].join('')], ['fontface', 'touch', 'csstransforms3d', 'generatedcontent']); tests['flexbox'] = function () { return testPropsAll('flexOrder') }; tests['flexbox-legacy'] = function () { return testPropsAll('boxDirection') }; tests['canvas'] = function () { var elem = document.createElement('canvas'); return !!(elem.getContext && elem.getContext('2d')) }; tests['canvastext'] = function () { return !!(Modernizr['canvas'] && is(document.createElement('canvas').getContext('2d').fillText, 'function')) }; tests['webgl'] = function () { try { var canvas = document.createElement('canvas'), ret; ret = !!(window.WebGLRenderingContext && (canvas.getContext('experimental-webgl') || canvas.getContext('webgl'))); canvas = undefined } catch (e) { ret = false } return ret }; tests['touch'] = function () { return Modernizr['touch'] }; tests['geolocation'] = function () { return !!navigator.geolocation }; tests['postmessage'] = function () { return !!window.postMessage }; tests['websqldatabase'] = function () { return !!window.openDatabase }; tests['indexedDB'] = function () { return !!testPropsAll("indexedDB", window) }; tests['hashchange'] = function () { return isEventSupported('hashchange', window) && (document.documentMode === undefined || document.documentMode > 7) }; tests['history'] = function () { return !!(window.history && history.pushState) }; tests['draganddrop'] = function () { var div = document.createElement('div'); return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div) }; tests['websockets'] = function () { for (var i = -1, len = cssomPrefixes.length; ++i < len; ) { if (window[cssomPrefixes[i] + 'WebSocket']) { return true } } return 'WebSocket' in window }; tests['rgba'] = function () { setCss('background-color:rgba(150,255,150,.5)'); return contains(mStyle.backgroundColor, 'rgba') }; tests['hsla'] = function () { setCss('background-color:hsla(120,40%,100%,.5)'); return contains(mStyle.backgroundColor, 'rgba') || contains(mStyle.backgroundColor, 'hsla') }; tests['multiplebgs'] = function () { setCss('background:url(https://),url(https://),red url(https://)'); return /(url\s*\(.*?){3}/.test(mStyle.background); }; tests['backgroundsize'] = function () { return testPropsAll('backgroundSize'); }; tests['borderimage'] = function () { return testPropsAll('borderImage'); }; tests['borderradius'] = function () { return testPropsAll('borderRadius'); }; tests['boxshadow'] = function () { return testPropsAll('boxShadow'); }; tests['textshadow'] = function () { return document.createElement('div').style.textShadow === ''; }; tests['opacity'] = function () { setCssAll('opacity:.55'); return /^0.55$/.test(mStyle.opacity) }; tests['cssanimations'] = function () { return testPropsAll('animationName') }; tests['csscolumns'] = function () { return testPropsAll('columnCount') }; tests['cssgradients'] = function () { var str1 = 'background-image:', str2 = 'gradient(linear,left top,right bottom,from(#9f9),to(white));', str3 = 'linear-gradient(left top,#9f9, white);'; setCss((str1 + '-webkit- '.split(' ').join(str2 + str1) + prefixes.join(str3 + str1)).slice(0, -str1.length)); return contains(mStyle.backgroundImage, 'gradient') }; tests['cssreflections'] = function () { return testPropsAll('boxReflect') }; tests['csstransforms'] = function () { return !!testPropsAll('transform') }; tests['csstransforms3d'] = function () { var ret = !!testPropsAll('perspective'); if (ret && 'webkitPerspective' in docElement.style) { ret = Modernizr['csstransforms3d'] } return ret }; tests['csstransitions'] = function () { return testPropsAll('transition') }; tests['fontface'] = function () { return Modernizr['fontface'] }; tests['generatedcontent'] = function () { return Modernizr['generatedcontent'] }; tests['video'] = function () { var elem = document.createElement('video'), bool = false; try { if (bool = !!elem.canPlayType) { bool = new Boolean(bool); bool.ogg = elem.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, ''); bool.h264 = elem.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ''); bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, '') } } catch (e) { } return bool }; tests['audio'] = function () { var elem = document.createElement('audio'), bool = false; try { if (bool = !!elem.canPlayType) { bool = new Boolean(bool); bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''); bool.mp3 = elem.canPlayType('audio/mpeg;').replace(/^no$/, ''); bool.wav = elem.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''); bool.m4a = (elem.canPlayType('audio/x-m4a;') || elem.canPlayType('audio/aac;')).replace(/^no$/, '') } } catch (e) { } return bool }; tests['localstorage'] = function () { try { localStorage.setItem(mod, mod); localStorage.removeItem(mod); return true } catch (e) { return false } }; tests['sessionstorage'] = function () { try { sessionStorage.setItem(mod, mod); sessionStorage.removeItem(mod); return true } catch (e) { return false } }; tests['webworkers'] = function () { return !!window.Worker }; tests['applicationcache'] = function () { return !!window.applicationCache }; tests['svg'] = function () { return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect }; tests['inlinesvg'] = function () { var div = document.createElement('div'); div.innerHTML = '<svg/>'; return (div.firstChild && div.firstChild.namespaceURI) == ns.svg }; tests['smil'] = function () { return !!document.createElementNS && /SVGAnimate/.test(toString.call(document.createElementNS(ns.svg, 'animate'))) }; tests['svgclippaths'] = function () { return !!document.createElementNS && /SVGClipPath/.test(toString.call(document.createElementNS(ns.svg, 'clipPath'))) }; function webforms() { Modernizr['input'] = (function (props) { for (var i = 0, len = props.length; i < len; i++) { attrs[props[i]] = !!(props[i] in inputElem) } if (attrs.list) { attrs.list = !!(document.createElement('datalist') && window.HTMLDataListElement) } return attrs })('autocomplete autofocus list placeholder max min multiple pattern required step'.split(' ')); Modernizr['inputtypes'] = (function (props) { for (var i = 0, bool, inputElemType, defaultView, len = props.length; i < len; i++) { inputElem.setAttribute('type', inputElemType = props[i]); bool = inputElem.type !== 'text'; if (bool) { inputElem.value = smile; inputElem.style.cssText = 'position:absolute;visibility:hidden;'; if (/^range$/.test(inputElemType) && inputElem.style.WebkitAppearance !== undefined) { docElement.appendChild(inputElem); defaultView = document.defaultView; bool = defaultView.getComputedStyle && defaultView.getComputedStyle(inputElem, null).WebkitAppearance !== 'textfield' && (inputElem.offsetHeight !== 0); docElement.removeChild(inputElem) } else if (/^(search|tel)$/.test(inputElemType)) { } else if (/^(url|email)$/.test(inputElemType)) { bool = inputElem.checkValidity && inputElem.checkValidity() === false } else if (/^color$/.test(inputElemType)) { docElement.appendChild(inputElem); docElement.offsetWidth; bool = inputElem.value != smile; docElement.removeChild(inputElem) } else { bool = inputElem.value != smile } } inputs[props[i]] = !!bool } return inputs })('search tel url email datetime date month week time datetime-local number range color'.split(' ')) } for (var feature in tests) { if (hasOwnProperty(tests, feature)) { featureName = feature.toLowerCase(); Modernizr[featureName] = tests[feature](); classes.push((Modernizr[featureName] ? '' : 'no-') + featureName) } } Modernizr.input || webforms(); Modernizr.addTest = function (feature, test) { if (typeof feature == 'object') { for (var key in feature) { if (hasOwnProperty(feature, key)) { Modernizr.addTest(key, feature[key]) } } } else { feature = feature.toLowerCase(); if (Modernizr[feature] !== undefined) { return Modernizr } test = typeof test == 'function' ? test() : test; docElement.className += ' ' + (test ? '' : 'no-') + feature; Modernizr[feature] = test } return Modernizr }; setCss(''); modElem = inputElem = null; (function (window, document) { var options = window.html5 || {}; var reSkip = /^<|^(?:button|form|map|select|textarea)$/i; var supportsHtml5Styles; var supportsUnknownElements; (function () { var a = document.createElement('a'); a.innerHTML = '<xyz></xyz>'; supportsHtml5Styles = ('hidden' in a); supportsUnknownElements = a.childNodes.length == 1 || (function () { try { (document.createElement)('a') } catch (e) { return true } var frag = document.createDocumentFragment(); return (typeof frag.cloneNode == 'undefined' || typeof frag.createDocumentFragment == 'undefined' || typeof frag.createElement == 'undefined') } ()) } ()); function addStyleSheet(ownerDocument, cssText) { var p = ownerDocument.createElement('p'), parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement; p.innerHTML = 'x<style>' + cssText + '</style>'; return parent.insertBefore(p.lastChild, parent.firstChild) } function getElements() { var elements = html5.elements; return typeof elements == 'string' ? elements.split(' ') : elements } function shivMethods(ownerDocument) { var cache = {}, docCreateElement = ownerDocument.createElement, docCreateFragment = ownerDocument.createDocumentFragment, frag = docCreateFragment(); ownerDocument.createElement = function (nodeName) { var node = (cache[nodeName] || (cache[nodeName] = docCreateElement(nodeName))).cloneNode(); return html5.shivMethods && node.canHaveChildren && !reSkip.test(nodeName) ? frag.appendChild(node) : node }; ownerDocument.createDocumentFragment = Function('h,f', 'return function(){' + 'var n=f.cloneNode(),c=n.createElement;' + 'h.shivMethods&&(' + getElements().join().replace(/\w+/g, function (nodeName) { cache[nodeName] = docCreateElement(nodeName); frag.createElement(nodeName); return 'c("' + nodeName + '")' }) + ');return n}')(html5, frag) } function shivDocument(ownerDocument) { var shived; if (ownerDocument.documentShived) { return ownerDocument } if (html5.shivCSS && !supportsHtml5Styles) { shived = !!addStyleSheet(ownerDocument, 'article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}' + 'audio{display:none}' + 'canvas,video{display:inline-block;*display:inline;*zoom:1}' + '[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}' + 'mark{background:#FF0;color:#000}') } if (!supportsUnknownElements) { shived = !shivMethods(ownerDocument) } if (shived) { ownerDocument.documentShived = shived } return ownerDocument } var html5 = { 'elements': options.elements || 'abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video', 'shivCSS': !(options.shivCSS === false), 'shivMethods': !(options.shivMethods === false), 'type': 'default', 'shivDocument': shivDocument }; window.html5 = html5; shivDocument(document) } (this, document)); Modernizr._version = version; Modernizr._prefixes = prefixes; Modernizr._domPrefixes = domPrefixes; Modernizr._cssomPrefixes = cssomPrefixes; Modernizr.mq = testMediaQuery; Modernizr.hasEvent = isEventSupported; Modernizr.testProp = function (prop) { return testProps([prop]) }; Modernizr.testAllProps = testPropsAll; Modernizr.testStyles = injectElementWithStyles; Modernizr.prefixed = function (prop, obj, elem) { if (!obj) { return testPropsAll(prop, 'pfx') } else { return testPropsAll(prop, obj, elem) } }; docElement.className = docElement.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') + (enableClasses ? ' js ' + classes.join(' ') : ''); return Modernizr })(this, this.document);
55 README.md
Source Rendered
... ... @@ -1,7 +1,56 @@
1 1 # modernizr-server-dotnet
2 2
3   -A library for accessing browser capabilities by [Modernizr](http://modernizr.com) on the server-side.
  3 +A library for accessing browser capabilities by [Modernizr](http://modernizr.com) on the server.
4 4
5   -Loosely translated from James Pearce's [modernizr-server](https://github.com/jamesgpearce/modernizr-server) into .NET 4.0.
  5 +Adapted from James Pearce's [modernizr-server](https://github.com/jamesgpearce/modernizr-server) into ASP.NET 4.0 with C# code-behind. Currently this is ASP.NET forms version. I plan on making an MVC version as well (see to-do's below).
6 6
7   -More coming soon!
  7 +## How to Use
  8 +For existing projects, include the server-side code on Default.aspx.cs in the Page_Load method of your default page. For new projects, you can simply copy Default.aspx and Default.aspx.cs and use that as a start to your default page.
  9 +
  10 +For new or existing projects, copy the ModernizrCookie.aspx and ModernizrCookie.aspx.cs files to your project. Also, grab the latest modernizr JS file from [Modernizr.com](http://modernizr.com) and include it in your project in the /js folder.
  11 +
  12 +In your web.config file, make sure to configure the session state if you have a particular preference on the session state mode. See [MSDN](msdn.microsoft.com/en-us/library/ms972429.aspx) for a brief overview of the session state configurations. I have the following (pretty close to default) configuration in the project:
  13 +
  14 + <sessionState mode="InProc" cookieless="false" timeout="30" />
  15 +
  16 +This mode is the fastest, and uses a cookie to store the SessionId. I also have a sliding timeout of 30 minutes.
  17 +
  18 +After you have completed the above, on any page in your site, you can retrieve the Modernizr session object and store it in a dynamic variable like so:
  19 +
  20 + dynamic Modernizr = Session["Modernizr"];
  21 +
  22 +You can see an example of this in VideoTest.aspx:
  23 +
  24 + dynamic Modernizr = Session["Modernizr"];
  25 + if (Modernizr != null)
  26 + {
  27 + // Session object was succesfully retrieved and set
  28 + if (Modernizr.video != null)
  29 + {
  30 + // at least one video property is supported
  31 + if (Modernizr.video.h264)
  32 + {
  33 + // browser supports h.264
  34 + }
  35 + if (Modernizr.video.webm)
  36 + {
  37 + // browser supports webm
  38 + }
  39 + if (Modernizr.video.ogg)
  40 + {
  41 + // browser supports ogg
  42 + }
  43 + }
  44 + }
  45 +
  46 +## How it Works
  47 +Much like the PHP implementation, the .NET version uses a combination of a cookie and the user's browsing session. The first time a user visits the site (specifically the default.aspx page), the server will redirect to a ModernizrCookie.aspx page, which is responsible for running the Modernizr JS and creating a serialized cookie that holds the browsers capabilities. This cookie is set to expire after 24 hours.
  48 +
  49 +After a cookie has been created (and on any new sessions for that particular user on that particular machine while the cookie is still valid) the server parses the cookie's data and places it in a dynamic object. The object is then stored in session and is available to any requests in that session.
  50 +
  51 +A bit of an improvement from the PHP version...If a cookie cannot be created the first time during a particular session, it will try again up to a set number of times. If it is still unsuccesful, the Modernizr capabilities will simply not be available to use. Therefore, it is important to always have a fallback in case the Modernizr session object is not available, or a particular
  52 +
  53 +## To-do's, etc.
  54 +1. This is not compatible with earlier versions of .NET (3.5, 2.0, etc.). The dynamic object I am using was introduced in .NET 4.0
  55 +2. Use with caution. I have not evaluated this for speed and efficiency in a production environment. This is merely for demonstration.
  56 +3. I plan on making an MVC version of this so it can be used in MVC applications.

No commit comments for this range

Something went wrong with that request. Please try again.