Tuesday, November 5, 2013

Cast everything in a C# enum to a space separated string!

public static string Render()
{
   var values = Enum.GetValues(typeof(Fixture));
   string spool = values.Cast<object>().Aggregate("", (current, value) => current + value +
         " ");
   return spool.Trim();
}

Monday, November 4, 2013

There does not seem to be a good way to decorate a textarea with readonly and still be able to "select all" on its contents in iOS.

I went Googling for a way around this problem today and found some pseudosolutions, but none of them panned out.

overflow-y: scroll;

...as a CSS style will put a vertical scrollbar on a div. overflow-x: scroll; will moreover put a horizontal scrollbar on a div. Please note that the addition of overflow-y: scroll; alone will also empower horizontal scrolling if you have a string of unbroken copy that is wider than the div itself present within the div such as, perhaps, supercalifragilisticexpialidocious.

Saturday, November 2, 2013

sniff and set HTML element styles with jQuery

$(function () {
   var loop = function () {
      var style = $("#brain").attr('style');
         if (style == "display: none;") {
            $("#brain").attr('style', "display: block;");
         } else {
            $("#brain").attr('style', "display: none;");
      }
   };
   var interval = setInterval(loop, 2000);
});

Styles.Render versus Scripts.Render

@Styles.Render("~/Content/css")
&
@Scripts.Render("~/bundles/modernizr")

 
 
 
 

...will both go fishing in BundleConfig.cs in the App_Start folder of an ASP.NET Web API with MVC Visual Studio 2013 project. Where they will find...

 
 
 
 

bundles.Add(new StyleBundle("~/Content/css").Include(
   "~/Content/bootstrap.css",
   "~/Content/site.css"));

&
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
   "~/Scripts/modernizr-*"));

 
 
 
 

...respectively. It is important to note the difference in the HTML that Styles and Scripts spit up to the browser however. The stuff above gives us back...

 
 
 
 

<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>

&
<script src="/Scripts/modernizr-2.6.2.js"></script>

 
 
 
 

...respectively.

Friday, November 1, 2013

mytextarea.setSelectionRange(0, mytextarea.value.length);

...is another way to NOT solve this problem. Hiss.

It turns out there is a way to spin a timer to wait for a JavaScript promise to resolve, you just have to use a piece of the DOM as a middleman.

widget.kickOffPromiseToUpdateTextArea();
var loop = function(){
   var textarea = widget.ourTextArea;
   var characterCount = textarea.innerHTML.length;
   if (characterCount != 0) {
      clearInterval(interval);
      alert('made it!');
      goDoSomethingElseWithFeedBack(textarea.innerHTML);
   } else {
      alert('not yet!');
   }
};
var interval = setInterval(loop, 6000);