Thursday, July 25, 2013

Javascript: Disable backspace key in browsers

Use:

 $(document).keydown(function (e) {
        var nodeName = e.target.nodeName.toLowerCase();

        if (e.which === 8) {
            if (((nodeName === 'input' && (e.target.type === 'text' || e.target.type === 'email')) ||
            nodeName === 'textarea') && e.target.readOnly == false) {
                // do nothing
            } else {
                e.preventDefault();
            }
        }
    });

Reference:
http://stackoverflow.com/questions/6309693/disabling-backspace-key-works-in-all-browsers-but-ie

OAuth Intro

There are the links of a great and simple intro video to understand OAuth:

 - Part1: http://www.youtube.com/watch?v=LRNg4tDtrkE
 - Part2: http://www.youtube.com/watch?v=2KG05SnAYlE
 - Part3: http://www.youtube.com/watch?v=qPHLsLlQ7Rw
 - Part4: http://www.youtube.com/watch?v=0PvQcLzVGF0

Here is the url with a nice explanation about how auth works:

http://hueniverse.com/oauth/guide/workflow/

Wednesday, July 24, 2013

HTML5: Prevent browser form autofill

You hace to use autocomplete="off" in your form tag:

<form name="form1" id="form1" method="post" autocomplete="off"
      action="http://www.example.com/form.cgi">
      Name: <input type="text" name="text1" /><br/>
      Address: <input type="text" name="text2" /><br/>
      Phone: <input type="text" name="text3" /><br/>
      Password: <input type="password" name="password" /><br/>
     <input type="Submit" name="Submit" value="Submit" />
</form>

Reference:
https://developer.mozilla.org/en-US/docs/Mozilla/How_to_Turn_Off_Form_Autocompletion

Tuesday, July 23, 2013

BackboneJS: click event is being triggered twice

In the view definition I had:

...
...
 // events
    ,events: {
        'click ': 'selectServiceEvent',
        'click a': 'learnMoreLinkEvent'
    }
...
...
,selectServiceEvent: function () {
        this.clickCard(); 
}

But when I was clicking the div generated by de view, the selectServiceEvent function was being triggered twice. The solution was add return false; to the selectServiceEvent function:

,selectServiceEvent: function () {
        this.clickCard(); 
        return false;
}

Monday, July 22, 2013

Google Chrome and WOFF font MIME type warnings

There is a link that explains the situation about the Google Chrome and WOFF font MIME type warnings:

 http://zduck.com/2013/google-chrome-and-woff-font-mime-type-warnings/

IIS7: Resource interpreted as Font but transferred with MIME type application/octet-stream:

With a site hosted in IIS I was getting this warning:

Resource interpreted as Font but transferred with MIME type application/octet-stream: "http://localhost/Website/assets/webfonts/mplus-1c-light-webfont.ttf". index.html:6
Resource interpreted as Font but transferred with MIME type application/octet-stream: "http://localhost/Website/assets/webfonts/mplus-1c-regular-webfont.ttf". index.html:6

The solution is:

1. Open IIS manager
2. Go to MIME types
3. Click on "add..."
4. Fill the fields:
   - File name extension: .woff
   - MIME Type: application/x-font-woff
5. Restart IIS.

References:
http://stackoverflow.com/questions/15521130/google-warning-resource-interpreted-as-font-but-transferred-with-mime-type-appl
http://stackoverflow.com/questions/3594823/mime-type-for-woff-fonts

JQuery: simple slider form

Here is a great and simple sample that shows a form using sliders without using any slider lib, just jquery and jqueryui:

http://webexpedition18.com/articles/how-to-create-a-multi-step-signup-form-with-css3-and-jquery/

Wednesday, July 3, 2013

LINQ: filter by two fields concatenation

When you hava an entiy with FirstName and LastName columns, and you need to filter by fullname, a quick solution is to filter by the fields value concatenation:

var agents = from a in DB.Agents
                                 where a.FirstName.Contains(name) ||
                                       a.LastName.Contains(name) ||
                                       String.Concat(a.FirstName, " ", a.LastName).Contains(name)
                                 select a;