jQuery style Ui dialog over flash banners


I was doing some extra job for one of the clients, some changes on the web site full of blinking flash banners.

Idea was to get users’ attention even more by displaying some floating windows… lovely …

Obvious choice would be jQuery modal dialog… So I made it … Unfortunately it has shown up that some of the flash banners remain ‘over’ the dialog, and some of them don’t. After digging into that I figured out that the reason behind that is one of flash parameters: “wmode” (thanks God this is not another inner flash issue).
From Adome Knowledge base:

wmode – Possible values: window, opaque, transparent. Sets the Window Mode property of the Flash movie for transparency, layering, and positioning in the browser.

  • window – movie plays in its own rectangular window on a web page.
  • opaque – the movie hides everything on the page behind it.
  • transparent – the background of the HTML page shows through all transparent portions of the movie. This option can slow animation performance.

So, to fix that You need to set this parameter to ‘transparent’. Fortunately all flash objects were placed with swfobject scripts. Sample code to fix that issue may look like may look like (video from YouTube):

    $(document).ready(function () {
        // The video to load.
        var videoID = "xxx";
        // Lets Flash from another domain call JavaScript
        var params = { allowScriptAccess: "always", wmode: "transparent" };
        // The element id of the Flash embed
        var atts = { id: "ytPlayer" };
        // All of the magic handled by SWFObject
        swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "&enablejsapi=1&playerapiid=player1",
                       "videoDiv", "420", "258", "8", null, null, params, atts);
    });

Hope this saves some of Your precious time…

Share

NLog binaries compiled to run under Medium Trusted environment

To save any one hassle with downloading NLog, StructureMap sources, updating assembly info in order to allow it to be run under Medium Trust, compiling them I have decided to attach a copy of compiled binaries.

Or, simply how to run Nlog on shared hosting (like GoDaddy and others).

NLog for Medium Trusted environment

Happy coding!

Share

Checkbox has to be ‘checked’ – with unobtrusive jQuery validation and ASP.NET MVC 3


Is it a pretty common scenario to have a checkbox on a form, that is required to be checked during POST-ing of a form. This usually happens when we have a typical ‘Agree to Terms and Conditions’ element. When I started to play with unobtrusive JavaScript validation in new ASP.NET MVC i was pretty sure that decorating boolean property with [Required] attribute will solve that issue. Surprisingly it doesn’t.

The key to this problem lies in interpretation of jQuery validation ‘required’ rule. I digged a little and find a specific code inside a jquery.validate.unobtrusive.js file:

adapters.add("required", function (options) {
  // jQuery Validate equates "required" with "mandatory" for checkbox elements
  if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") {
    setValidationValues(options, "required", true);
  }
});

As You can see rule does not applies to checkboxes. Simple solution to that would be to either change this code (which we really do not want to do) or create a new specific adapter. I do not know why it is like that – i can guess that it might be for a backward compatibility. Anyway, to make that work we will start by creating a custom attribute.

public class BooleanRequired : RequiredAttribute, IClientValidatable {        

        public BooleanRequired() {

        }

        public override bool IsValid(object value) {
            return value != null && (bool)value == true;
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) {
            return new ModelClientValidationRule[] { new ModelClientValidationRule() { ValidationType = "brequired", ErrorMessage = this.ErrorMessage } };
        }
    }

As You can see it inherits from common RequiredAttribute. Moreover it implements IClientValidateable. This is to make assure that rule will be propagated to client side (jQuery validation) as well. The key part here is GetClientValidationRules method (adapter) where we define new, custom ValidationType called for the purpose of this post, as a ‘brequired’. To make that work, a specific JavaScript code has to be prepare that adds our custom adapter:


jQuery.validator.unobtrusive.adapters.add("brequired", function (options) {
    //b-required for checkboxes
    if (options.element.tagName.toUpperCase() == "INPUT" && options.element.type.toUpperCase() == "CHECKBOX") {
        //setValidationValues(options, "required", true);
        options.rules["required"] = true;
        if (options.message) {
            options.messages["required"] = options.message;
        }
    }
});

All that is left is to mark properties with newly created BooleanRequired attribute.


[BooleanRequired]
public bool AcceptTermsAndCond { get; set' }

Happy coding!

Share

Web designers vs Web developers

The best picture I have found so far (from http://www.landingpages.co.il):

web designers vs web developers

Share

Silverlight, Flash and HTML5 on job market


There have been a lot of buzz after unfortunate interview where by Bob Muglia admitted that: our (Microsoft) strategy with Silverlight has shifted. That somehow disappointed me, as I was planning to take a closer look at Silverlight. Well, according to guys from Redmond, future belongs to HTML5 – whatever that means.
I have decided to check how does the market look like in industry of so called RIA – Rich Internet Applications. The most proper check is to compare demands for appropriate skills. I have used indeed.com to perform my research.
job-market-absolute

No surprise so far. Knowledge of Flash is the most demanded nowadays. Although it is clearly visible that it is not growing as fast as it used to. Please, note that measures were taken using absolute  scale. Much more interesting thing happen when we tke a look at this graph in relative scale.

And that is something that makes You think. Comparing to Silverlight and Flash, demand for HTML5 skills has recently exploded.

I know that it far too soon to talk about HTML5.

I know that it will not substitute Flash nowadays, and will definably not replace Silverlight for  companies that run ‘back office’ tools on it.

I know …

But still, one picture is worth a thousand words

Share

Weird exception (with the simplest solution) after playing with Entity Framework


I have been playing with Entity framework Code-First approach (this is definitely the way I am going to use for my next project, i love it). Anyway, doesn’t matter if it is Code-First or Database-First approach, from time to time I keep on getting an exception:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

It always takes few minutes to remember – what was that. Ah… It happens when You do not initialize DateTime properties when adding objects to database. Of course, that don’t have to be Your problem dear reader but as it happened to me for the third time I assume It should be pretty common one.

Seriously, if for the third time You dig for solution of a known to You problem – that means You are getting old buddy.

Share